package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;

import mail.Mail;
import mail.MyModelEmail;
import todo.MyTask;
import tools.DeletebyID;
import tools.OptionReader;
import calendar.CheckboxCalendar;
import calendar.Event;

/**
 * Klasse repräsentiert die Tagesansicht
 * 
 * @author Michi
 * 
 */
public class DayView extends JFrame {

	/**
	 * Member Section
	 */
	private static final long serialVersionUID = -5371762544102266127L;
	private Connection connection = Test.getConnection();
	private JPanel contentPane;
	private JTextField titelTextField;
	private JTextField beginDateTextField;
	private JTextField endDateTextField;
	private JTextField ortTextField;
	private JTextField teilnehmerTextField;
	private JComboBox kalenderTextField;
	private JPanel eventListPanel;
	private JLabel DateLabel;
	private JLabel DayLabel;
	private JScrollPane eventListScrollPane;
	private JPanel dayInfoPanel;
	private JPanel eventDetailsPanel;
	private JLabel titleLabel;
	private JLabel beginnLabel;
	private JLabel endeLabel;
	private JLabel ortLabel;
	private JLabel teilnehmerLabel;
	private JLabel kalenderLabel;
	private JLabel notizLabel;
	private JPanel buttonPanel;
	private JButton deleteButton;
	private JButton editButton;
	private JButton sendButton;
	private int hoeheGebTerminPanel = 50;
	private int breiteTerminPanel = 350;
	private int hoeheTerminPanel = 75;
	private int counterTP = 0;
	private int counterGTP = 0;
	private JTextArea notizTextArea;
	private JLabel noEventsLabel;
	private OptionReader or;
	private String[] windowColorsSeperated;
	private int r;
	private int g;
	private int b;
	private Object actDeleteCandidate;
	private String activeTerminArt;
	private JPanel clickedPanel;
	private int idCal;
	private Statement stat = null;
	private LinkedList<Integer> participants = new LinkedList<Integer>();
	private DayView dv = this;
	private int idEvents;
	// Uhrzeit Format (0 = 24h // 1 = AmPm)
	int format = 0;
	// Sprache (0 = de // 1 = en // 2 = latein)
	int speak = 0;

	String[] fensterName = { "Tagesansicht vom ", "Day View of the ",
			"Die visum a " };

	String[] titel = { "Titel", "heading", "titulus" };
	String[] begin = { "Begin", "begin", "initium" };
	String[] ende = { "Ende", "end", "finis" };
	String[] ort = { "Ort", "location", "locus" };
	String[] teilnehmer = { "Teilnehmer", "participants", "auditor" };
	String[] kalender = { "Kalender", "calendar", "calendarium" };
	String[] notiz = { "Notiz", "note", "hypomnema" };

	String[] loeschen = { "Löschen", "Delete", "Restinguere" };
	String[] bearbeiten = { "Bearbeiten", "Edit", "Incudo" };
	String[] speichern = { "Speichern", "Save", "Demuto" };
	String[] senden = { "Senden", "Send", "Allegare" };

	String[] noTerm = { "Heute sind keine Termine vorhanden.",
			"There are no events available.", "Non sunt palmulae praesto." };

	String[] jahreKlammer = { " Jahre)", " years)", " annalis)" };
	String[] uhr = { " Uhr", " o'clock", " Horologium" };

	String[] mo = { "Montag", "Monday", "Lunae dies" };
	String[] di = { "Dienstag", "Tuesday", "Martis dies" };
	String[] mi = { "Mittwoch", "Wednesday", "Mercurii dies" };
	String[] don = { "Donnerstag", "Thursday", "Iovis dies" };
	String[] fr = { "Freitag", "Friday", "Veneris dies" };
	String[] sa = { "Samstag", "Saturday", "Saturni dies" };
	String[] so = { "Sonntag", "Sunday", "Solis dies " };
	String[] endevorbegin = { "Ende des Termins liegt vor dem Begin.",
			"End of the event is prior to the Begin.",
			"Initium finis est prior quam res." };
	String[] unbekannterfehler = { "Unbekannter Fehler.", "Unknown Error.",
			"Ignoto erroris est." };
	private JLabel label;
	private JComboBox beginTag;
	private JComboBox beginMonat;
	private JComboBox beginJahr;
	private JComboBox beginStunde;
	private JComboBox beginMinute;
	private JLabel lblUhr_1;
	private JLabel lblUhr_2;
	private JLabel label_1;
	private JComboBox endeTag;
	private JComboBox endeMonat;
	private JComboBox endeJahr;
	private JComboBox endeStunde;
	private JComboBox endeMinute;
	private LinkedList<CheckboxCalendar> cals = new LinkedList<CheckboxCalendar>();
	private String[] calDropdown;
	private DayPanel uebergabePanel;
	private WeekDayPanel uebergabePanel2;
	private JButton participantsbutton;
	private LinkedList<String> emailLinkedList;

	/**
	 * Launch the application.
	 */

	/**
	 * Konstruktor
	 * 
	 * @param cv
	 *            Instanz der Monatsansicht
	 * @param dp
	 *            Instanz des DayPanels dieses Tages
	 * @wbp.parser.constructor
	 */
	@SuppressWarnings("deprecation")
	public DayView(final CalView cv, final DayPanel dp) {

		setUebergabePanel(dp);

		or = new OptionReader();
		try {
			or.getOpionsFromFile();
		} catch (IOException e2) {

			e2.printStackTrace();
		}
		// Setzt Fensternamen
		setTitle(fensterName[speak]
				+ (dp.getDate().getDate() + "." + (dp.getDate().getMonth() + 1)
						+ "." + (dp.getDate().getYear() + 1900)));

		String windowColors = or.getColorSetting();
		windowColorsSeperated = windowColors.split(",");
		r = Integer.parseInt(windowColorsSeperated[0]);
		g = Integer.parseInt(windowColorsSeperated[1]);
		b = Integer.parseInt(windowColorsSeperated[2]);

		speak = Integer.parseInt(or.getLanguage());
		format = Integer.parseInt(or.getAllOpt3());

		setMinimumSize(new Dimension(1100, 600));
		setMaximumSize(new Dimension(1200, 600));
		setSize(new Dimension(905, 600));
		setPreferredSize(new Dimension(1100, 600));

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);

		contentPane = new JPanel();
		contentPane.setBackground(new Color(r, g, b));
		contentPane.setSize(new Dimension(850, 600));
		contentPane.setPreferredSize(new Dimension(1100, 600));
		contentPane.setMinimumSize(new Dimension(1100, 600));
		contentPane.setMaximumSize(new Dimension(1200, 600));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[] { 390, 20, 400, 0 };
		gbl_contentPane.rowHeights = new int[] { 520, 0, 0 };
		gbl_contentPane.columnWeights = new double[] { 1.0, 1.0, 1.0,
				Double.MIN_VALUE };
		gbl_contentPane.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		contentPane.setLayout(gbl_contentPane);

		JPanel leftSidePanel = new JPanel();
		leftSidePanel.setSize(new Dimension(350, 400));
		leftSidePanel.setPreferredSize(new Dimension(350, 400));
		leftSidePanel.setMinimumSize(new Dimension(350, 400));
		leftSidePanel.setMaximumSize(new Dimension(350, 400));
		GridBagConstraints gbc_leftSidePanel = new GridBagConstraints();
		gbc_leftSidePanel.fill = GridBagConstraints.BOTH;
		gbc_leftSidePanel.insets = new Insets(0, 0, 5, 5);
		gbc_leftSidePanel.gridx = 0;
		gbc_leftSidePanel.gridy = 0;
		contentPane.add(leftSidePanel, gbc_leftSidePanel);
		leftSidePanel.setLayout(new BorderLayout(0, 0));

		dayInfoPanel = new JPanel();
		dayInfoPanel.setBackground(new Color(r, g, b));
		dayInfoPanel.setSize(new Dimension(350, 100));
		dayInfoPanel.setPreferredSize(new Dimension(350, 100));
		dayInfoPanel.setMinimumSize(new Dimension(350, 100));
		dayInfoPanel.setMaximumSize(new Dimension(350, 100));
		leftSidePanel.add(dayInfoPanel, BorderLayout.NORTH);
		dayInfoPanel.setLayout(new GridLayout(0, 1, 0, 0));

		DateLabel = new JLabel(" Date");
		DateLabel.setFont(new Font("Lucida Grande", Font.BOLD, 60));
		dayInfoPanel.add(DateLabel);

		DayLabel = new JLabel("   Day");
		dayInfoPanel.add(DayLabel);

		eventListScrollPane = new JScrollPane();
		eventListScrollPane.setSize(new Dimension(350, 300));
		eventListScrollPane.setPreferredSize(new Dimension(350, 300));
		eventListScrollPane.setMinimumSize(new Dimension(350, 300));
		eventListScrollPane.setMaximumSize(new Dimension(350, 300));
		leftSidePanel.add(eventListScrollPane, BorderLayout.CENTER);

		eventListPanel = new JPanel();
		eventListPanel.setSize(new Dimension(350, 360));
		eventListPanel.setPreferredSize(new Dimension(350, 360));
		eventListPanel.setMinimumSize(new Dimension(350, 360));
		eventListPanel.setMaximumSize(new Dimension(350, 360));
		eventListScrollPane.setViewportView(eventListPanel);

		JSeparator separator = new JSeparator();
		separator.setOrientation(SwingConstants.VERTICAL);
		GridBagConstraints gbc_separator = new GridBagConstraints();
		gbc_separator.fill = GridBagConstraints.BOTH;
		gbc_separator.insets = new Insets(0, 0, 5, 5);
		gbc_separator.gridx = 1;
		gbc_separator.gridy = 0;
		contentPane.add(separator, gbc_separator);

		eventDetailsPanel = new JPanel();
		eventDetailsPanel.setBackground(new Color(r, g, b));
		eventDetailsPanel.setSize(new Dimension(330, 400));
		eventDetailsPanel.setPreferredSize(new Dimension(450, 400));
		eventDetailsPanel.setMinimumSize(new Dimension(550, 400));
		eventDetailsPanel.setMaximumSize(new Dimension(550, 400));
		GridBagConstraints gbc_eventDetailsPanel = new GridBagConstraints();
		gbc_eventDetailsPanel.insets = new Insets(0, 0, 5, 0);
		gbc_eventDetailsPanel.fill = GridBagConstraints.BOTH;
		gbc_eventDetailsPanel.gridx = 2;
		gbc_eventDetailsPanel.gridy = 0;
		contentPane.add(eventDetailsPanel, gbc_eventDetailsPanel);
		GridBagLayout gbl_eventDetailsPanel = new GridBagLayout();
		gbl_eventDetailsPanel.columnWidths = new int[] { 90, 0, 0, 0, 0, 0, 0,
				0, 0, 0 };
		gbl_eventDetailsPanel.rowHeights = new int[] { 40, 40, 40, 40, 40, 40,
				250, 0 };
		gbl_eventDetailsPanel.columnWeights = new double[] { 0.0, 1.0, 1.0,
				1.0, 0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE };
		gbl_eventDetailsPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, Double.MIN_VALUE };
		eventDetailsPanel.setLayout(gbl_eventDetailsPanel);

		titleLabel = new JLabel(titel[speak]);
		titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_titleLabel = new GridBagConstraints();
		gbc_titleLabel.fill = GridBagConstraints.BOTH;
		gbc_titleLabel.insets = new Insets(0, 0, 5, 5);
		gbc_titleLabel.gridx = 0;
		gbc_titleLabel.gridy = 0;
		eventDetailsPanel.add(titleLabel, gbc_titleLabel);

		titelTextField = new JTextField();
		titelTextField.setDisabledTextColor(Color.BLACK);
		titelTextField.setEditable(false);
		GridBagConstraints gbc_titelTextField = new GridBagConstraints();
		gbc_titelTextField.gridwidth = 7;
		gbc_titelTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_titelTextField.insets = new Insets(0, 0, 5, 5);
		gbc_titelTextField.gridx = 1;
		gbc_titelTextField.gridy = 0;
		eventDetailsPanel.add(titelTextField, gbc_titelTextField);
		titelTextField.setColumns(10);

		beginnLabel = new JLabel(begin[speak]);
		beginnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_beginnLabel = new GridBagConstraints();
		gbc_beginnLabel.anchor = GridBagConstraints.EAST;
		gbc_beginnLabel.fill = GridBagConstraints.VERTICAL;
		gbc_beginnLabel.insets = new Insets(0, 0, 5, 5);
		gbc_beginnLabel.gridx = 0;
		gbc_beginnLabel.gridy = 1;
		eventDetailsPanel.add(beginnLabel, gbc_beginnLabel);

		beginDateTextField = new JTextField();
		beginDateTextField.setDisabledTextColor(Color.BLACK);
		beginDateTextField.setEditable(false);
		GridBagConstraints gbc_beginDateTextField = new GridBagConstraints();
		gbc_beginDateTextField.gridwidth = 7;
		gbc_beginDateTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginDateTextField.insets = new Insets(0, 0, 5, 5);
		gbc_beginDateTextField.gridx = 1;
		gbc_beginDateTextField.gridy = 1;
		beginDateTextField.setVisible(true);
		eventDetailsPanel.add(beginDateTextField, gbc_beginDateTextField);
		titelTextField.setColumns(10);

		// Tag //

		String[] tagesArray = new String[31];

		for (int i = 0; i < 31; i++) {
			String s = "";
			if (i < 9) {
				s = "0";
			}
			s += Integer.toString(i + 1);
			tagesArray[i] = s;
		}

		beginTag = new JComboBox(tagesArray);
		beginTag.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginTag = new GridBagConstraints();
		gbc_beginTag.insets = new Insets(0, 0, 5, 5);
		gbc_beginTag.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginTag.gridx = 1;
		gbc_beginTag.gridy = 1;
		beginTag.setFocusable(false);
		beginTag.setVisible(false);

		eventDetailsPanel.add(beginTag, gbc_beginTag);

		/*
		 * 
		 * // tag.setSelectedIndex(t - 1); // // tag.setBounds(160, 56, 70, 20);
		 * // centerpanel.add(tag);
		 * 
		 * // Jahr //
		 * 
		 * String[] jahreArray = new String[30];
		 * 
		 * int jz = (new Date().getYear()) + 1900; for (int i = 0; i < 30; i++)
		 * { jahreArray[i] = Integer.toString(jz); jz++; }
		 * 
		 * final JComboBox jahr = new JComboBox(jahreArray); // Test ob date in
		 * Vergangenheit ist
		 * 
		 * 
		 * 
		 * //int pos = (y - (new Date().getYear() + 1900));
		 * 
		 * if (pos < 0) { jahr.setSelectedIndex(0); } else {
		 * jahr.setSelectedIndex(pos); } // ! jahr.setBounds(310, 56, 85, 20);
		 * centerpanel.add(jahr);
		 * 
		 * // Monat //
		 * 
		 * final JComboBox monat = new JComboBox(monatsArray);
		 * monat.setSelectedIndex(m - 1);
		 * 
		 * monat.setBounds(235, 56, 70, 20); centerpanel.add(monat);
		 * 
		 * 
		 * // Stunde //
		 * 
		 * String[] stundenArray = new String[24];
		 * 
		 * for (int i = 0; i < 24; i++) {
		 * 
		 * stundenArray[i] = Integer.toString(i); }
		 * 
		 * final JComboBox stunde = new JComboBox(stundenArray);
		 * 
		 * stunde.setSelectedIndex(8);
		 * 
		 * stunde.setBounds(420, 56, 70, 20); centerpanel.add(stunde);
		 * 
		 * // .getSelectedItem()
		 * 
		 * // Minute //
		 * 
		 * 
		 * final JComboBox minute = new JComboBox(minutenArray);
		 * 
		 * minute.setBounds(495, 56, 70, 20); centerpanel.add(minute);
		 */

		// MONAT
		String[] monatsArray = new String[12];

		for (int i = 0; i < 12; i++) {
			String s = "";
			if (i < 9) {
				s = "0";
			}
			s += Integer.toString(i + 1);
			monatsArray[i] = s;
		}

		beginMonat = new JComboBox(monatsArray);
		beginMonat.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginMonat = new GridBagConstraints();
		gbc_beginMonat.insets = new Insets(0, 0, 5, 5);
		gbc_beginMonat.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginMonat.gridx = 2;
		gbc_beginMonat.gridy = 1;

		beginMonat.setFocusable(false);
		beginMonat.setVisible(false);

		eventDetailsPanel.add(beginMonat, gbc_beginMonat);

		// JAHR

		String[] jahreArray = new String[30];

		int jz = (new Date().getYear()) + 1900;
		for (int i = 0; i < 30; i++) {
			jahreArray[i] = Integer.toString(jz);
			jz++;
		}

		beginJahr = new JComboBox(jahreArray);
		beginJahr.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginJahr = new GridBagConstraints();
		gbc_beginJahr.insets = new Insets(0, 0, 5, 5);
		gbc_beginJahr.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginJahr.gridx = 3;
		gbc_beginJahr.gridy = 1;
		beginJahr.setFocusable(false);
		beginJahr.setVisible(false);

		eventDetailsPanel.add(beginJahr, gbc_beginJahr);

		label_1 = new JLabel("     ");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.anchor = GridBagConstraints.EAST;
		gbc_label_1.gridx = 4;
		gbc_label_1.gridy = 1;
		eventDetailsPanel.add(label_1, gbc_label_1);

		// STUNDE

		String[] stundenArray = new String[24];

		for (int i = 0; i < 24; i++) {

			stundenArray[i] = Integer.toString(i);
		}

		beginStunde = new JComboBox(stundenArray);
		beginStunde.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginStunde = new GridBagConstraints();
		gbc_beginStunde.insets = new Insets(0, 0, 5, 5);
		gbc_beginStunde.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginStunde.gridx = 5;
		gbc_beginStunde.gridy = 1;
		beginStunde.setFocusable(false);
		beginStunde.setVisible(false);
		eventDetailsPanel.add(beginStunde, gbc_beginStunde);

		// Minute

		String[] minutenArray = new String[4];

		minutenArray[0] = "00";
		minutenArray[1] = "15";
		minutenArray[2] = "30";
		minutenArray[3] = "45";

		beginMinute = new JComboBox(minutenArray);
		beginMinute.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginMinute = new GridBagConstraints();
		gbc_beginMinute.insets = new Insets(0, 0, 5, 5);
		gbc_beginMinute.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginMinute.gridx = 6;
		gbc_beginMinute.gridy = 1;
		beginMinute.setFocusable(false);
		beginMinute.setVisible(false);
		eventDetailsPanel.add(beginMinute, gbc_beginMinute);

		lblUhr_1 = new JLabel("Uhr");
		GridBagConstraints gbc_lblUhr_1 = new GridBagConstraints();
		gbc_lblUhr_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblUhr_1.gridx = 7;
		gbc_lblUhr_1.gridy = 1;
		lblUhr_1.setVisible(false);
		eventDetailsPanel.add(lblUhr_1, gbc_lblUhr_1);

		// //////////////// ENDE /////////////////

		endeLabel = new JLabel(ende[speak]);
		endeLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_endeLabel = new GridBagConstraints();
		gbc_endeLabel.fill = GridBagConstraints.BOTH;
		gbc_endeLabel.insets = new Insets(0, 0, 5, 5);
		gbc_endeLabel.gridx = 0;
		gbc_endeLabel.gridy = 2;
		eventDetailsPanel.add(endeLabel, gbc_endeLabel);

		endDateTextField = new JTextField();
		endDateTextField.setDisabledTextColor(Color.BLACK);
		endDateTextField.setEditable(false);
		GridBagConstraints gbc_endDateTextField = new GridBagConstraints();
		gbc_endDateTextField.gridwidth = 7;
		gbc_endDateTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_endDateTextField.insets = new Insets(0, 0, 5, 5);
		gbc_endDateTextField.gridx = 1;
		gbc_endDateTextField.gridy = 2;
		endDateTextField.setVisible(true);
		eventDetailsPanel.add(endDateTextField, gbc_endDateTextField);
		titelTextField.setColumns(10);

		endeTag = new JComboBox(tagesArray);
		endeTag.setPreferredSize(new Dimension(30, 20));
		endeTag.setFocusable(false);
		GridBagConstraints gbc_endeTag = new GridBagConstraints();
		gbc_endeTag.insets = new Insets(0, 0, 5, 5);
		gbc_endeTag.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeTag.gridx = 1;
		gbc_endeTag.gridy = 2;
		endeTag.setVisible(false);
		eventDetailsPanel.add(endeTag, gbc_endeTag);

		endeMonat = new JComboBox(monatsArray);
		endeMonat.setPreferredSize(new Dimension(30, 20));
		endeMonat.setFocusable(false);
		GridBagConstraints gbc_endeMonat = new GridBagConstraints();
		gbc_endeMonat.insets = new Insets(0, 0, 5, 5);
		gbc_endeMonat.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeMonat.gridx = 2;
		gbc_endeMonat.gridy = 2;
		endeMonat.setVisible(false);
		eventDetailsPanel.add(endeMonat, gbc_endeMonat);

		endeJahr = new JComboBox(jahreArray);
		endeJahr.setPreferredSize(new Dimension(50, 20));
		endeJahr.setFocusable(false);
		GridBagConstraints gbc_endeJahr = new GridBagConstraints();
		gbc_endeJahr.insets = new Insets(0, 0, 5, 5);
		gbc_endeJahr.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeJahr.gridx = 3;
		gbc_endeJahr.gridy = 2;
		endeJahr.setVisible(false);
		eventDetailsPanel.add(endeJahr, gbc_endeJahr);

		endeStunde = new JComboBox(stundenArray);
		endeStunde.setPreferredSize(new Dimension(30, 20));
		endeStunde.setFocusable(false);
		GridBagConstraints gbc_endeStunde = new GridBagConstraints();
		gbc_endeStunde.insets = new Insets(0, 0, 5, 5);
		gbc_endeStunde.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeStunde.gridx = 5;
		gbc_endeStunde.gridy = 2;
		endeStunde.setVisible(false);
		eventDetailsPanel.add(endeStunde, gbc_endeStunde);

		endeMinute = new JComboBox(minutenArray);
		endeMinute.setPreferredSize(new Dimension(30, 20));
		endeMinute.setFocusable(false);
		GridBagConstraints gbc_endeMinute = new GridBagConstraints();
		gbc_endeMinute.insets = new Insets(0, 0, 5, 5);
		gbc_endeMinute.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeMinute.gridx = 6;
		gbc_endeMinute.gridy = 2;
		endeMinute.setVisible(false);
		eventDetailsPanel.add(endeMinute, gbc_endeMinute);

		lblUhr_2 = new JLabel("Uhr");
		GridBagConstraints gbc_lblUhr_2 = new GridBagConstraints();
		gbc_lblUhr_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblUhr_2.gridx = 7;
		gbc_lblUhr_2.gridy = 2;
		lblUhr_2.setVisible(false);
		eventDetailsPanel.add(lblUhr_2, gbc_lblUhr_2);

		ortLabel = new JLabel(ort[speak]);
		ortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_ortLabel = new GridBagConstraints();
		gbc_ortLabel.fill = GridBagConstraints.BOTH;
		gbc_ortLabel.insets = new Insets(0, 0, 5, 5);
		gbc_ortLabel.gridx = 0;
		gbc_ortLabel.gridy = 3;
		eventDetailsPanel.add(ortLabel, gbc_ortLabel);

		ortTextField = new JTextField();
		ortTextField.setEditable(false);
		ortTextField.setDisabledTextColor(Color.BLACK);
		GridBagConstraints gbc_ortTextField = new GridBagConstraints();
		gbc_ortTextField.gridwidth = 7;
		gbc_ortTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_ortTextField.insets = new Insets(0, 0, 5, 5);
		gbc_ortTextField.gridx = 1;
		gbc_ortTextField.gridy = 3;
		eventDetailsPanel.add(ortTextField, gbc_ortTextField);
		ortTextField.setColumns(10);

		teilnehmerLabel = new JLabel(teilnehmer[speak]);
		teilnehmerLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_teilnehmerLabel = new GridBagConstraints();
		gbc_teilnehmerLabel.fill = GridBagConstraints.BOTH;
		gbc_teilnehmerLabel.insets = new Insets(0, 0, 5, 5);
		gbc_teilnehmerLabel.gridx = 0;
		gbc_teilnehmerLabel.gridy = 4;
		eventDetailsPanel.add(teilnehmerLabel, gbc_teilnehmerLabel);

		teilnehmerTextField = new JTextField();
		teilnehmerTextField.setDisabledTextColor(Color.BLACK);
		teilnehmerTextField.setEditable(false);
		GridBagConstraints gbc_teilnehmerTextField = new GridBagConstraints();
		gbc_teilnehmerTextField.gridwidth = 6;
		gbc_teilnehmerTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_teilnehmerTextField.insets = new Insets(0, 0, 5, 5);
		gbc_teilnehmerTextField.gridx = 1;
		gbc_teilnehmerTextField.gridy = 4;
		eventDetailsPanel.add(teilnehmerTextField, gbc_teilnehmerTextField);
		teilnehmerTextField.setColumns(10);

		participantsbutton = new JButton("+");
		GridBagConstraints gbc_participantsbutton = new GridBagConstraints();
		gbc_participantsbutton.insets = new Insets(0, 0, 5, 5);
		gbc_participantsbutton.gridx = 7;
		gbc_participantsbutton.gridy = 4;
		participantsbutton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				idEvents = (Integer) getActDeleteCandidate();
				AddContactWindow acw = new AddContactWindow(dv, false);
				acw.setVisible(true);

			}

		});
		participantsbutton.setEnabled(false);

		eventDetailsPanel.add(participantsbutton, gbc_participantsbutton);

		kalenderLabel = new JLabel(kalender[speak]);
		kalenderLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_kalenderLabel = new GridBagConstraints();
		gbc_kalenderLabel.fill = GridBagConstraints.BOTH;
		gbc_kalenderLabel.insets = new Insets(0, 0, 5, 5);
		gbc_kalenderLabel.gridx = 0;
		gbc_kalenderLabel.gridy = 5;
		eventDetailsPanel.add(kalenderLabel, gbc_kalenderLabel);

		// Kalender

		ResultSet idsCalendar;
		cals.clear();
		try {

			stat = connection.createStatement();
			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

			idsCalendar = stat
					.executeQuery("SELECT idCalendar, name, idCreator FROM Calendar WHERE idUser = "
							+ Test.iduser + ";");
			while (idsCalendar.next()) {
				CheckboxCalendar temp = new CheckboxCalendar(
						idsCalendar.getInt("idCalendar"),
						idsCalendar.getString("name"),
						idsCalendar.getInt("idCreator"));
				cals.add(temp);
			}
		} catch (SQLException e1) {
			JOptionPane
					.showMessageDialog(
							null,
							"Es konnte keine Verbindung zur Datenbank hergestellt werden",
							"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
			e1.printStackTrace();
		}

		calDropdown = new String[cals.size()];
		for (int i = 0; i < cals.size(); i++) {
			calDropdown[i] = cals.get(i).getName();
		}

		kalenderTextField = new JComboBox(calDropdown);
		kalenderTextField.setEnabled(false);
		// kalenderTextField.setDisabledTextColor(Color.BLACK);
		GridBagConstraints gbc_kalenderTextField = new GridBagConstraints();
		gbc_kalenderTextField.gridwidth = 7;
		gbc_kalenderTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_kalenderTextField.insets = new Insets(0, 0, 5, 5);
		gbc_kalenderTextField.gridx = 1;
		gbc_kalenderTextField.gridy = 5;
		eventDetailsPanel.add(kalenderTextField, gbc_kalenderTextField);
		// kalenderTextField.setColumns(10);

		label = new JLabel("  ");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 0);
		gbc_label.gridx = 8;
		gbc_label.gridy = 5;
		eventDetailsPanel.add(label, gbc_label);

		notizLabel = new JLabel(notiz[speak]);
		notizLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_notizLabel = new GridBagConstraints();

		gbc_notizLabel.fill = GridBagConstraints.BOTH;
		gbc_notizLabel.insets = new Insets(0, 0, 0, 5);
		gbc_notizLabel.gridx = 0;
		gbc_notizLabel.gridy = 6;
		eventDetailsPanel.add(notizLabel, gbc_notizLabel);

		notizTextArea = new JTextArea();
		notizTextArea.setDisabledTextColor(Color.BLACK);
		notizTextArea.setEditable(false);
		notizTextArea.setLineWrap(true);
		notizTextArea.setWrapStyleWord(true);
		JScrollPane notizScrollPane = new JScrollPane(notizTextArea);
		GridBagConstraints gbc_notizTextArea = new GridBagConstraints();
		gbc_notizTextArea.gridwidth = 8;
		gbc_notizTextArea.fill = GridBagConstraints.BOTH;
		gbc_notizTextArea.gridx = 1;
		gbc_notizTextArea.gridy = 6;
		eventDetailsPanel.add(notizScrollPane, gbc_notizTextArea);
		notizTextArea.setBorder(kalenderTextField.getBorder());

		JPanel dummyPanel1 = new JPanel();
		dummyPanel1.setBackground(new Color(r, g, b));
		dummyPanel1.setVisible(false);
		GridBagConstraints gbc_dummyPanel1 = new GridBagConstraints();
		gbc_dummyPanel1.insets = new Insets(0, 0, 0, 5);
		gbc_dummyPanel1.fill = GridBagConstraints.BOTH;
		gbc_dummyPanel1.gridx = 0;
		gbc_dummyPanel1.gridy = 1;
		contentPane.add(dummyPanel1, gbc_dummyPanel1);

		JPanel dummyPanel2 = new JPanel();
		dummyPanel2.setBackground(new Color(r, g, b));
		dummyPanel2.setVisible(false);
		GridBagConstraints gbc_dummyPanel2 = new GridBagConstraints();
		gbc_dummyPanel2.insets = new Insets(0, 0, 0, 5);
		gbc_dummyPanel2.fill = GridBagConstraints.BOTH;
		gbc_dummyPanel2.gridx = 1;
		gbc_dummyPanel2.gridy = 1;
		contentPane.add(dummyPanel2, gbc_dummyPanel2);

		buttonPanel = new JPanel();
		buttonPanel.setBackground(new Color(r, g, b));
		buttonPanel.setSize(new Dimension(400, 50));
		buttonPanel.setMinimumSize(new Dimension(400, 50));
		buttonPanel.setMaximumSize(new Dimension(400, 50));
		buttonPanel.setPreferredSize(new Dimension(400, 50));
		GridBagConstraints gbc_buttonPanel = new GridBagConstraints();
		gbc_buttonPanel.anchor = GridBagConstraints.EAST;
		gbc_buttonPanel.gridx = 2;
		gbc_buttonPanel.gridy = 1;
		contentPane.add(buttonPanel, gbc_buttonPanel);
		GridBagLayout gbl_buttonPanel = new GridBagLayout();
		gbl_buttonPanel.columnWidths = new int[] { 0, 0, 0, 0 };
		gbl_buttonPanel.rowHeights = new int[] { 0, 0, 0, 0 };
		gbl_buttonPanel.columnWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_buttonPanel.rowWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		buttonPanel.setLayout(gbl_buttonPanel);

		deleteButton = new JButton(loeschen[speak]);
		deleteButton.setEnabled(false);
		deleteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String s = getActDeleteCandidate() + "";
				DeletebyID.deleteEvent(s);
				cv.setEs();
				cv.setTs();
				cv.getMainInstance().updateCalendar();
				forceRepaint();
				dispose();

				int y = 0;
				Date[] da = cal.MonthData.getDateArray(dp.getDate());
				for (int q = 0; q < da.length; q++) {
					if (da[q].equals(dp.getDate())) {
						y = q;
					}
				}

				new DayView(cv, (DayPanel) cv.getCalGroundPanel().getComponent(
						y)).setVisible(true);

				// cv.getMainInstance().updateCalendar();
				// new DayView(cv, dp).setVisible(true);

			}
		});
		deleteButton.setSize(new Dimension(110, 29));
		deleteButton.setMaximumSize(new Dimension(110, 29));
		deleteButton.setMinimumSize(new Dimension(110, 29));
		deleteButton.setPreferredSize(new Dimension(110, 29));
		GridBagConstraints gbc_deleteButton = new GridBagConstraints();
		gbc_deleteButton.insets = new Insets(0, 0, 5, 5);
		gbc_deleteButton.gridx = 0;
		gbc_deleteButton.gridy = 1;
		buttonPanel.add(deleteButton, gbc_deleteButton);

		editButton = new JButton(bearbeiten[speak]);
		editButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String text = arg0.getActionCommand();
				// /////////// BEARBEITEN
				// ///////////////////////////////////////////////////

				if (text.equals(bearbeiten[speak])) {

					titelTextField.setEditable(true);
					beginJahr.setFocusable(true); // setSelectable(true);
					beginMonat.setFocusable(true);
					beginTag.setFocusable(true);
					beginStunde.setFocusable(true);
					beginMinute.setFocusable(true);
					ortTextField.setFocusable(true);

					endeJahr.setFocusable(true);
					endeMonat.setFocusable(true);
					endeTag.setFocusable(true);
					endeStunde.setFocusable(true);
					endeMinute.setFocusable(true);

					ortTextField.setEditable(true);
					kalenderTextField.setEnabled(true);
					notizTextArea.setEditable(true);
					participantsbutton.setEnabled(true);

					beginDateTextField.setVisible(false);
					endDateTextField.setVisible(false);
					beginJahr.setVisible(true); // setSelectable(true);
					beginMonat.setVisible(true);
					beginTag.setVisible(true);
					beginStunde.setVisible(true);
					beginMinute.setVisible(true);
					endeJahr.setVisible(true);
					endeMonat.setVisible(true);
					endeTag.setVisible(true);
					endeStunde.setVisible(true);
					endeMinute.setVisible(true);

					lblUhr_1.setVisible(true);
					lblUhr_2.setVisible(true);

					// SET DATE TO RIGHT DATE //

					String begindate = beginDateTextField.getText();
					String enddate = endDateTextField.getText();

					// ARRAY: 0 = Tag, 1 = Monat, 2 = Stunde, 3 = Minute

					int[] begindatearray = getComboInts(begindate);
					int[] enddatearray = getComboInts(enddate);

					Date date = dp.getDate();

					int byear = date.getYear();
					beginJahr.setSelectedIndex(byear - new Date().getYear());

					int bmonat;
					if (begindatearray[1] != 0) {
						bmonat = begindatearray[1];
					} else {
						bmonat = date.getMonth() + 1;
					}
					beginMonat.setSelectedIndex(bmonat - 1);

					int btag;
					if (begindatearray[0] != 0) {
						btag = begindatearray[0];
					} else {
						btag = date.getDate();
					}
					beginTag.setSelectedIndex(btag - 1);

					int bhour = begindatearray[2];
					beginStunde.setSelectedIndex(bhour);

					int bminute = begindatearray[3];
					if (bminute == 0) {
						beginMinute.setSelectedIndex(0);
					} else if (bminute > 0 && bminute < 16) {
						beginMinute.setSelectedIndex(1);
					} else if (bminute > 15 && bminute < 31) {
						beginMinute.setSelectedIndex(2);
					} else {
						beginMinute.setSelectedIndex(3);
					}

					int eyear = date.getYear();
					endeJahr.setSelectedIndex(eyear - new Date().getYear());

					int emonat;
					if (enddatearray[1] != 0) {
						emonat = enddatearray[1];
					} else {
						emonat = date.getMonth() + 1;
					}
					endeMonat.setSelectedIndex(emonat - 1);

					int etag;
					if (enddatearray[0] != 0) {
						etag = enddatearray[0];
					} else {
						etag = date.getDate();
					}
					endeTag.setSelectedIndex(etag - 1);

					int ehour = enddatearray[2];
					endeStunde.setSelectedIndex(ehour);

					int eminute = enddatearray[3];
					if (eminute == 0) {
						endeMinute.setSelectedIndex(0);
					} else if (eminute > 0 && eminute < 16) {
						endeMinute.setSelectedIndex(1);
					} else if (eminute > 15 && eminute < 31) {
						endeMinute.setSelectedIndex(2);
					} else {
						endeMinute.setSelectedIndex(3);
					}

					editButton.setText(speichern[speak]);

				}

				// ///////////// SPEICHERN
				// ////////////////////////////////////////////////////
				if (text.equals(speichern[speak])) {

					titelTextField.setEditable(false);

					beginJahr.setFocusable(false);
					beginMonat.setFocusable(false);
					beginTag.setFocusable(false);
					beginStunde.setFocusable(false);
					beginMinute.setFocusable(false);

					endeJahr.setFocusable(false);
					endeMonat.setFocusable(false);
					endeTag.setFocusable(false);
					endeStunde.setFocusable(false);
					endeMinute.setFocusable(false);

					ortTextField.setEditable(false);
					teilnehmerTextField.setEditable(false);
					participantsbutton.setEnabled(false);
					kalenderTextField.setEditable(false);
					notizTextArea.setEditable(false);
					kalenderTextField.setEnabled(false);
					beginDateTextField.setVisible(true);
					endDateTextField.setVisible(true);
					beginJahr.setVisible(false); // setSelectable(true);
					beginMonat.setVisible(false);
					beginTag.setVisible(false);
					beginStunde.setVisible(false);
					beginMinute.setVisible(false);
					endeJahr.setVisible(false);
					endeMonat.setVisible(false);
					endeTag.setVisible(false);
					endeStunde.setVisible(false);
					endeMinute.setVisible(false);

					lblUhr_1.setVisible(false);
					lblUhr_2.setVisible(false);

					editButton.setText(bearbeiten[speak]);

					@SuppressWarnings("rawtypes")
					SwingWorker worker = new SwingWorker() {

						@Override
						public Object doInBackground() throws Exception {

							// ////DATE//////

							// BEGIN//
							int beginY = Integer.parseInt((String) beginJahr
									.getSelectedItem());
							int beginM = beginMonat.getSelectedIndex() + 1;
							int beginD = beginTag.getSelectedIndex() + 1;
							int beginH = beginStunde.getSelectedIndex();
							int beginMin = Integer
									.parseInt((String) beginMinute
											.getSelectedItem());

							Date begin = makeDate(beginY, beginM, beginD,
									beginH, beginMin);

							// ENDE//
							int nbeginY = Integer.parseInt((String) endeJahr
									.getSelectedItem());
							int nbeginM = endeMonat.getSelectedIndex() + 1;
							int nbeginD = endeTag.getSelectedIndex() + 1;
							int nbeginH = endeStunde.getSelectedIndex();
							int nbeginMin = Integer
									.parseInt((String) endeMinute
											.getSelectedItem());

							Date end = makeDate(nbeginY, nbeginM, nbeginD,
									nbeginH, nbeginMin);

							int selectedToDo = kalenderTextField
									.getSelectedIndex();

							int idTodo = cals.get(selectedToDo).getIdCalendar();

							System.out.println(idTodo);

							// / Test ob Ende nach Begin liegt
							if ((testMonth(beginY, beginM, beginD, beginH,
									beginMin) == false)
									|| (testMonth(nbeginY, nbeginM, nbeginD,
											nbeginH, nbeginMin) == false)) {

							} else if (end.before(begin)) {

								new NotifyFrame(endevorbegin[speak])
										.setVisible(true);

							} else {

								// Dates in einen String der korrekten Form
								// bringen.
								SimpleDateFormat sdf = new SimpleDateFormat(
										"yyyy-MM-dd HH:mm:ss");

								StringBuilder sBBegin = new StringBuilder(sdf
										.format(begin));

								StringBuilder sBEnd = new StringBuilder(sdf
										.format(end));

								String beginString = sBBegin.toString();
								String endString = sBEnd.toString();

								// Liest die Werte aus

								String name = getTitelTextField().getText();
								String ort = getOrtTextField().getText();
								String notiz = getNotizTextArea().getText();
								int EventId = (Integer) getActDeleteCandidate();

								stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");
								connection.setAutoCommit(false);
								PreparedStatement pstmt = connection
										.prepareStatement("UPDATE `sopra-ws12-awesome_fireballs`.`Events` SET `idCalendar`=?, `name`=?, `startdate`=?, `enddate`=?, `location`=?, `description`=? WHERE `idEvents`=?;");

								System.out.println("HUUUUUUU");

								// Diese 2 mit Kalender ersetzen
								pstmt.setInt(1, idTodo);
								pstmt.setString(2, name);
								pstmt.setString(3, beginString);
								pstmt.setString(4, endString);
								pstmt.setString(5, ort);
								pstmt.setString(6, notiz);
								pstmt.setInt(7, EventId);
								pstmt.addBatch();

								ResultSet nextparticipantid = stat
										.executeQuery("SELECT idparticipants FROM `sopra-ws12-awesome_fireballs`.participants ORDER BY idparticipants DESC LIMIT 1;");
								int nextpartid = 0;
								while (nextparticipantid.next()) {
									nextpartid = nextparticipantid.getInt(1) + 1;
								}

								PreparedStatement ppstmt = connection
										.prepareStatement("INSERT INTO `sopra-ws12-awesome_fireballs`.participants VALUES(?, ?, ?)");

								System.out.println(participants.size());
								System.out.println(participants.toString());

								ResultSet rsparti = getParticipantsEvent(EventId);

								while (rsparti.next()) {
									for (int i = 0; i < participants.size(); i++) {
										if (rsparti.getInt("idAdress") == participants
												.get(i)) {
											participants.remove(i);
											i = 0;
										}
									}

								}

								for (int i = 0; i < participants.size(); i++) {

									ppstmt.setInt(1, nextpartid + i);
									ppstmt.setInt(2, EventId);
									ppstmt.setInt(3, participants.get(i));
									ppstmt.addBatch();

								}
								System.out.println("TEST");

								System.out.println(pstmt.toString());
								System.out.println(ppstmt.toString());
								pstmt.executeBatch();
								ppstmt.executeBatch();
								connection.commit();
								connection.setAutoCommit(true);
								participants.clear();

							}

							return stat;
						}

						public void done() {

							if (emailLinkedList != null) {
								if (emailLinkedList.size() > 0) {
									Mail temp = new Mail();

									temp.setTo(emailLinkedList);

									temp.setBetreff("Einladung zu Termin: "
											+ titelTextField.getText());

									temp.setText(idEvents + "");

									MyModelEmail mme = new MyModelEmail();
									mme.sendMail(temp, true);

								}
							}

							cv.setEs();
							cv.setTs();
							cv.getMainInstance().updateCalendar();
							forceRepaint();
							dispose();

							int y = 0;
							Date[] da = cal.MonthData.getDateArray(dp.getDate());
							for (int q = 0; q < da.length; q++) {
								if (da[q].equals(dp.getDate())) {
									y = q;
								}
							}

							new DayView(cv, (DayPanel) cv.getCalGroundPanel()
									.getComponent(y)).setVisible(true);

						}

					};

					worker.execute();
				}
			}
		});
		editButton.setSize(new Dimension(110, 29));
		editButton.setMaximumSize(new Dimension(110, 29));
		editButton.setPreferredSize(new Dimension(110, 29));
		editButton.setMinimumSize(new Dimension(110, 29));
		editButton.setEnabled(false);
		GridBagConstraints gbc_editButton = new GridBagConstraints();
		gbc_editButton.insets = new Insets(0, 0, 5, 5);
		gbc_editButton.gridx = 1;
		gbc_editButton.gridy = 1;
		buttonPanel.add(editButton, gbc_editButton);

		sendButton = new JButton(senden[speak]);
		sendButton.setVisible(false);
		sendButton.setEnabled(false);
		sendButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				@SuppressWarnings("unused")
				Mail temp = new Mail();
				if (getActiveTerminArt().contains("G")) {

				}

				if (getActiveTerminArt().contains("E")) {

				}

				if (getActiveTerminArt().contains("T")) {

				}

			}
		});
		sendButton.setSize(new Dimension(110, 29));
		sendButton.setPreferredSize(new Dimension(110, 29));
		sendButton.setMaximumSize(new Dimension(110, 29));
		sendButton.setMinimumSize(new Dimension(110, 29));
		GridBagConstraints gbc_sendButton = new GridBagConstraints();
		gbc_sendButton.insets = new Insets(0, 0, 5, 0);
		gbc_sendButton.gridx = 2;
		gbc_sendButton.gridy = 1;
		buttonPanel.add(sendButton, gbc_sendButton);
		noEventsLabel = new JLabel(noTerm[speak]);
		noEventsLabel.setVisible(false);
		noEventsLabel.setFont(new Font("Lucida Grande", Font.BOLD, 18));
		eventListPanel.add(noEventsLabel);

		// Datenübernahme

		// Tag oben links wird gesetzt
		getDateLabel().setText(dp.getDate().getDate() + "");
		// volles Datum oben rechts wird gesetzt
		getDayLabel().setText(
				intToDay(dp.getDate().getDay()) + ", " + dp.getDate().getDate()
						+ "." + (dp.getDate().getMonth() + 1) + "."
						+ (dp.getDate().getYear() + 1900));

		if (dp.getAllCalendarItems().size() < 1
				|| dp.getAllCalendarItems() == null) {
			getNoEventsLabel().setVisible(true);
		}

		init1(dp);

	}

	/**
	 * erzeugt TerminPanel Liste
	 * 
	 * @param dp
	 *            Instanz des Panels welches die Tagesansichta ufruft
	 */
	@SuppressWarnings("deprecation")
	public void init1(DayPanel dp) {

		getEventListScrollPane().setViewportView(null);
		getEventListPanel().removeAll();
		counterTP = 0;

		// Termin Panels werden erzeugt
		for (int i = 0; i < dp.getAllCalendarItems().size(); i++) {
			final TerminPanel tp = new TerminPanel();
			final GebTerminPanel gtp = new GebTerminPanel();

			// Abprüfen ob an Position i ein Task ist und wenn ja, Task
			// speichern
			if (dp.getAllCalendarItems().get(i) instanceof MyTask) {
				MyTask temp = (MyTask) dp.getAllCalendarItems().get(i);
				tp.getEventNameTextField().setText(temp.getName());
				tp.getEventNameTextField().setCaretPosition(0);

				tp.getEventDateEndTextField().setText(
						temp.getEnddate().getDate() + "."
								+ (temp.getEnddate().getMonth() + 1) + "."
								+ (temp.getEnddate().getYear() + 1900));
				tp.getEventDateEndTextField().setCaretPosition(0);
				tp.setNotiz(temp.getDescription());
				tp.setPanelType("T");
				tp.changeColor(Color.gray);
				tp.setTerminArt(temp.getId());

			}

			// Abprüfen ob an Position i ein Event ist und wenn ja, Event
			// speichern
			if (dp.getAllCalendarItems().get(i) instanceof Event) {
				Event temp = (Event) dp.getAllCalendarItems().get(i);
				tp.getEventNameTextField().setText(temp.getName());

				String start = "";
				String end = "";

				// Ruft Methode eventString auf!
				String[] startend = eventString(temp.getStart(), temp.getEnd(),
						dp.getDate());
				start = startend[0];
				end = startend[1];
				tp.getEventDateStartTextField().setText(start);
				tp.getEventDateEndTextField().setText(end);
				tp.setNotiz(temp.getDescription());
				tp.setOrt(temp.getOrt());
				tp.setPanelType("E");
				tp.changeColor(Color.white);
				tp.setTerminArt(temp.getEventID());

			}

			// Abprüfen ob an Position i ein Geburtstag ist und wenn ja,
			// Geburtstag speichern
			if (dp.getAllCalendarItems().get(i) instanceof String[]) {

				String[] temp = (String[]) dp.getAllCalendarItems().get(i);
				// Person temp = (Person) dp.getAllCalendarItems().get(i);

				gtp.getBirthdayNameTextField().setText(
						temp[0] + " " + temp[1] + " (" + temp[2]
								+ jahreKlammer[speak]);

				gtp.setPanelType("G");

			}

			// MouseListener Section
			tp.getEventNameTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});
			tp.getEventNamePanel().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});

			// tp.getEventDatePanelStart().addMouseListener(new MouseAdapter() {
			// @Override
			// public void mouseClicked(MouseEvent e) {
			// setDetailsWindow(tp);
			// }
			// });
			tp.getEventDatePanel().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});

			// tp.getEventDatePanelEnd().addMouseListener(new MouseAdapter() {
			// @Override
			// public void mouseClicked(MouseEvent e) {
			// setDetailsWindow(tp);
			// }
			// });

			tp.getEventDateStartTextField().addMouseListener(
					new MouseAdapter() {
						@Override
						public void mouseClicked(MouseEvent e) {
							setDetailsWindow(tp);
							setClickedPanel(tp);
							init1(getUebergabePanel());
						}
					});

			tp.getEventDateEndTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});

			tp.getEventBeginnTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});

			tp.getEventEndeTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init1(getUebergabePanel());
				}
			});

			gtp.getBirthdayNameTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(gtp);
					setClickedPanel(gtp);
					init1(getUebergabePanel());
				}
			});

			// MouseListener Ende

			if (tp.getPanelType() == "E" || tp.getPanelType() == "T") {
				if (getClickedPanel() != null && compare(getClickedPanel(), tp)) {
					System.out.println("erkannt");
					tp.setBorder(BorderFactory
							.createLineBorder(Color.yellow, 1));
				}
				getEventListPanel().add(tp);
				counterTP++;
			}

			if (gtp.getPanelType() == "G") {
				if (getClickedPanel() != null
						&& compare(getClickedPanel(), gtp)) {
					System.out.println("erkannt");
					gtp.setBorder(BorderFactory.createLineBorder(Color.yellow,
							1));
				}
				getEventListPanel().add(gtp);
				counterGTP++;
			}
		}

		eventListPanel
				.setPreferredSize(new Dimension(
						breiteTerminPanel,
						((counterTP * hoeheTerminPanel) + (counterGTP * hoeheGebTerminPanel))));

		getEventListScrollPane().setViewportView(getEventListPanel());

	}

	@SuppressWarnings("deprecation")
	public DayView(final WeekView wv, final WeekDayPanel wdp) {

		setUebergabePanel2(wdp);

		or = new OptionReader();
		try {
			or.getOpionsFromFile();
		} catch (IOException e2) {

			e2.printStackTrace();
		}

		String windowColors = or.getColorSetting();
		windowColorsSeperated = windowColors.split(",");
		r = Integer.parseInt(windowColorsSeperated[0]);
		g = Integer.parseInt(windowColorsSeperated[1]);
		b = Integer.parseInt(windowColorsSeperated[2]);

		speak = Integer.parseInt(or.getLanguage());
		format = Integer.parseInt(or.getAllOpt3());

		setMinimumSize(new Dimension(1100, 600));
		setMaximumSize(new Dimension(1200, 600));
		setSize(new Dimension(905, 600));
		setPreferredSize(new Dimension(1100, 600));

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);

		contentPane = new JPanel();
		contentPane.setBackground(new Color(r, g, b));
		contentPane.setSize(new Dimension(850, 600));
		contentPane.setPreferredSize(new Dimension(850, 600));
		contentPane.setMinimumSize(new Dimension(850, 600));
		contentPane.setMaximumSize(new Dimension(850, 600));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[] { 390, 20, 370, 0 };
		gbl_contentPane.rowHeights = new int[] { 520, 0, 0 };
		gbl_contentPane.columnWeights = new double[] { 1.0, 1.0, 1.0,
				Double.MIN_VALUE };
		gbl_contentPane.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		contentPane.setLayout(gbl_contentPane);

		JPanel leftSidePanel = new JPanel();
		leftSidePanel.setBackground(new Color(r, g, b));
		leftSidePanel.setSize(new Dimension(350, 400));
		leftSidePanel.setPreferredSize(new Dimension(350, 400));
		leftSidePanel.setMinimumSize(new Dimension(350, 400));
		leftSidePanel.setMaximumSize(new Dimension(350, 400));
		GridBagConstraints gbc_leftSidePanel = new GridBagConstraints();
		gbc_leftSidePanel.fill = GridBagConstraints.BOTH;
		gbc_leftSidePanel.insets = new Insets(0, 0, 5, 5);
		gbc_leftSidePanel.gridx = 0;
		gbc_leftSidePanel.gridy = 0;
		contentPane.add(leftSidePanel, gbc_leftSidePanel);
		leftSidePanel.setLayout(new BorderLayout(0, 0));

		dayInfoPanel = new JPanel();
		dayInfoPanel.setBackground(new Color(r, g, b));
		dayInfoPanel.setSize(new Dimension(350, 100));
		dayInfoPanel.setPreferredSize(new Dimension(350, 100));
		dayInfoPanel.setMinimumSize(new Dimension(350, 100));
		dayInfoPanel.setMaximumSize(new Dimension(350, 100));
		leftSidePanel.add(dayInfoPanel, BorderLayout.NORTH);
		dayInfoPanel.setLayout(new GridLayout(0, 1, 0, 0));

		DateLabel = new JLabel(" Date");
		DateLabel.setFont(new Font("Lucida Grande", Font.BOLD, 60));
		dayInfoPanel.add(DateLabel);

		DayLabel = new JLabel("   Day");
		dayInfoPanel.add(DayLabel);

		eventListScrollPane = new JScrollPane();
		eventListScrollPane.setSize(new Dimension(350, 300));
		eventListScrollPane.setPreferredSize(new Dimension(350, 300));
		eventListScrollPane.setMinimumSize(new Dimension(350, 300));
		eventListScrollPane.setMaximumSize(new Dimension(350, 300));
		leftSidePanel.add(eventListScrollPane, BorderLayout.CENTER);

		eventListPanel = new JPanel();
		eventListPanel.setSize(new Dimension(350, 360));
		eventListPanel.setPreferredSize(new Dimension(350, 360));
		eventListPanel.setMinimumSize(new Dimension(350, 360));
		eventListPanel.setMaximumSize(new Dimension(350, 360));
		eventListScrollPane.setViewportView(eventListPanel);

		JSeparator separator = new JSeparator();
		separator.setOrientation(SwingConstants.VERTICAL);
		GridBagConstraints gbc_separator = new GridBagConstraints();
		gbc_separator.fill = GridBagConstraints.BOTH;
		gbc_separator.insets = new Insets(0, 0, 5, 5);
		gbc_separator.gridx = 1;
		gbc_separator.gridy = 0;
		contentPane.add(separator, gbc_separator);

		eventDetailsPanel = new JPanel();
		eventDetailsPanel.setBackground(new Color(r, g, b));
		eventDetailsPanel.setSize(new Dimension(330, 400));
		eventDetailsPanel.setPreferredSize(new Dimension(450, 400));
		eventDetailsPanel.setMinimumSize(new Dimension(550, 400));
		eventDetailsPanel.setMaximumSize(new Dimension(550, 400));
		GridBagConstraints gbc_eventDetailsPanel = new GridBagConstraints();
		gbc_eventDetailsPanel.insets = new Insets(0, 0, 5, 0);
		gbc_eventDetailsPanel.fill = GridBagConstraints.BOTH;
		gbc_eventDetailsPanel.gridx = 2;
		gbc_eventDetailsPanel.gridy = 0;
		contentPane.add(eventDetailsPanel, gbc_eventDetailsPanel);
		GridBagLayout gbl_eventDetailsPanel = new GridBagLayout();
		gbl_eventDetailsPanel.columnWidths = new int[] { 90, 0, 0, 0, 0, 0, 0,
				0, 0, 0 };
		gbl_eventDetailsPanel.rowHeights = new int[] { 40, 40, 40, 40, 40, 40,
				250, 0 };
		gbl_eventDetailsPanel.columnWeights = new double[] { 0.0, 1.0, 1.0,
				1.0, 0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE };
		gbl_eventDetailsPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, Double.MIN_VALUE };
		eventDetailsPanel.setLayout(gbl_eventDetailsPanel);

		titleLabel = new JLabel(begin[speak]);
		titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_titleLabel = new GridBagConstraints();
		gbc_titleLabel.fill = GridBagConstraints.BOTH;
		gbc_titleLabel.insets = new Insets(0, 0, 5, 5);
		gbc_titleLabel.gridx = 0;
		gbc_titleLabel.gridy = 0;
		eventDetailsPanel.add(titleLabel, gbc_titleLabel);

		titelTextField = new JTextField();
		titelTextField.setDisabledTextColor(Color.BLACK);
		titelTextField.setEditable(false);
		GridBagConstraints gbc_titelTextField = new GridBagConstraints();
		gbc_titelTextField.gridwidth = 7;
		gbc_titelTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_titelTextField.insets = new Insets(0, 0, 5, 5);
		gbc_titelTextField.gridx = 1;
		gbc_titelTextField.gridy = 0;
		eventDetailsPanel.add(titelTextField, gbc_titelTextField);
		titelTextField.setColumns(10);

		beginnLabel = new JLabel(begin[speak]);
		beginnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_beginnLabel = new GridBagConstraints();
		gbc_beginnLabel.fill = GridBagConstraints.BOTH;
		gbc_beginnLabel.insets = new Insets(0, 0, 5, 5);
		gbc_beginnLabel.gridx = 0;
		gbc_beginnLabel.gridy = 1;
		eventDetailsPanel.add(beginnLabel, gbc_beginnLabel);

		beginDateTextField = new JTextField();
		beginDateTextField.setDisabledTextColor(Color.BLACK);
		beginDateTextField.setEditable(false);
		GridBagConstraints gbc_beginDateTextField = new GridBagConstraints();
		gbc_beginDateTextField.gridwidth = 7;
		gbc_beginDateTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginDateTextField.insets = new Insets(0, 0, 5, 5);
		gbc_beginDateTextField.gridx = 1;
		gbc_beginDateTextField.gridy = 1;
		beginDateTextField.setVisible(true);
		eventDetailsPanel.add(beginDateTextField, gbc_beginDateTextField);
		titelTextField.setColumns(10);

		// Tag //

		String[] tagesArray = new String[31];

		for (int i = 0; i < 31; i++) {
			String s = "";
			if (i < 9) {
				s = "0";
			}
			s += Integer.toString(i + 1);
			tagesArray[i] = s;
		}

		beginTag = new JComboBox(tagesArray);
		beginTag.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginTag = new GridBagConstraints();
		gbc_beginTag.insets = new Insets(0, 0, 5, 5);
		gbc_beginTag.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginTag.gridx = 1;
		gbc_beginTag.gridy = 1;
		beginTag.setFocusable(false);
		beginTag.setVisible(false);

		eventDetailsPanel.add(beginTag, gbc_beginTag);

		// MONAT
		String[] monatsArray = new String[12];

		for (int i = 0; i < 12; i++) {
			String s = "";
			if (i < 9) {
				s = "0";
			}
			s += Integer.toString(i + 1);
			monatsArray[i] = s;
		}

		beginMonat = new JComboBox(monatsArray);
		beginMonat.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginMonat = new GridBagConstraints();
		gbc_beginMonat.insets = new Insets(0, 0, 5, 5);
		gbc_beginMonat.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginMonat.gridx = 2;
		gbc_beginMonat.gridy = 1;

		beginMonat.setFocusable(false);
		beginMonat.setVisible(false);

		eventDetailsPanel.add(beginMonat, gbc_beginMonat);

		// JAHR

		String[] jahreArray = new String[30];

		int jz = (new Date().getYear()) + 1900;
		for (int i = 0; i < 30; i++) {
			jahreArray[i] = Integer.toString(jz);
			jz++;
		}

		beginJahr = new JComboBox(jahreArray);
		beginJahr.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginJahr = new GridBagConstraints();
		gbc_beginJahr.insets = new Insets(0, 0, 5, 5);
		gbc_beginJahr.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginJahr.gridx = 3;
		gbc_beginJahr.gridy = 1;
		beginJahr.setFocusable(false);
		beginJahr.setVisible(false);

		eventDetailsPanel.add(beginJahr, gbc_beginJahr);

		label_1 = new JLabel("     ");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.anchor = GridBagConstraints.EAST;
		gbc_label_1.gridx = 4;
		gbc_label_1.gridy = 1;
		eventDetailsPanel.add(label_1, gbc_label_1);

		// STUNDE

		String[] stundenArray = new String[24];

		for (int i = 0; i < 24; i++) {

			stundenArray[i] = Integer.toString(i);
		}

		beginStunde = new JComboBox(stundenArray);
		beginStunde.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginStunde = new GridBagConstraints();
		gbc_beginStunde.insets = new Insets(0, 0, 5, 5);
		gbc_beginStunde.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginStunde.gridx = 5;
		gbc_beginStunde.gridy = 1;
		beginStunde.setFocusable(false);
		beginStunde.setVisible(false);
		eventDetailsPanel.add(beginStunde, gbc_beginStunde);

		// Minute

		String[] minutenArray = new String[4];

		minutenArray[0] = "00";
		minutenArray[1] = "15";
		minutenArray[2] = "30";
		minutenArray[3] = "45";

		beginMinute = new JComboBox(minutenArray);
		beginMinute.setPreferredSize(new Dimension(50, 20));
		GridBagConstraints gbc_beginMinute = new GridBagConstraints();
		gbc_beginMinute.insets = new Insets(0, 0, 5, 5);
		gbc_beginMinute.fill = GridBagConstraints.HORIZONTAL;
		gbc_beginMinute.gridx = 6;
		gbc_beginMinute.gridy = 1;
		beginMinute.setFocusable(false);
		beginMinute.setVisible(false);
		eventDetailsPanel.add(beginMinute, gbc_beginMinute);

		lblUhr_1 = new JLabel("Uhr");
		GridBagConstraints gbc_lblUhr_1 = new GridBagConstraints();
		gbc_lblUhr_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblUhr_1.gridx = 7;
		gbc_lblUhr_1.gridy = 1;
		lblUhr_1.setVisible(false);
		eventDetailsPanel.add(lblUhr_1, gbc_lblUhr_1);

		// //////////////// ENDE /////////////////

		endeLabel = new JLabel(ende[speak]);
		endeLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_endeLabel = new GridBagConstraints();
		gbc_endeLabel.fill = GridBagConstraints.BOTH;
		gbc_endeLabel.insets = new Insets(0, 0, 5, 5);
		gbc_endeLabel.gridx = 0;
		gbc_endeLabel.gridy = 2;
		eventDetailsPanel.add(endeLabel, gbc_endeLabel);

		endDateTextField = new JTextField();
		endDateTextField.setDisabledTextColor(Color.BLACK);
		endDateTextField.setEditable(false);
		GridBagConstraints gbc_endDateTextField = new GridBagConstraints();
		gbc_endDateTextField.gridwidth = 7;
		gbc_endDateTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_endDateTextField.insets = new Insets(0, 0, 5, 5);
		gbc_endDateTextField.gridx = 1;
		gbc_endDateTextField.gridy = 2;
		endDateTextField.setVisible(true);
		eventDetailsPanel.add(endDateTextField, gbc_endDateTextField);
		titelTextField.setColumns(10);

		endeTag = new JComboBox(tagesArray);
		endeTag.setPreferredSize(new Dimension(30, 20));
		endeTag.setFocusable(false);
		GridBagConstraints gbc_endeTag = new GridBagConstraints();
		gbc_endeTag.insets = new Insets(0, 0, 5, 5);
		gbc_endeTag.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeTag.gridx = 1;
		gbc_endeTag.gridy = 2;
		endeTag.setVisible(false);
		eventDetailsPanel.add(endeTag, gbc_endeTag);

		endeMonat = new JComboBox(monatsArray);
		endeMonat.setPreferredSize(new Dimension(30, 20));
		endeMonat.setFocusable(false);
		GridBagConstraints gbc_endeMonat = new GridBagConstraints();
		gbc_endeMonat.insets = new Insets(0, 0, 5, 5);
		gbc_endeMonat.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeMonat.gridx = 2;
		gbc_endeMonat.gridy = 2;
		endeMonat.setVisible(false);
		eventDetailsPanel.add(endeMonat, gbc_endeMonat);

		endeJahr = new JComboBox(jahreArray);
		endeJahr.setPreferredSize(new Dimension(50, 20));
		endeJahr.setFocusable(false);
		GridBagConstraints gbc_endeJahr = new GridBagConstraints();
		gbc_endeJahr.insets = new Insets(0, 0, 5, 5);
		gbc_endeJahr.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeJahr.gridx = 3;
		gbc_endeJahr.gridy = 2;
		endeJahr.setVisible(false);
		eventDetailsPanel.add(endeJahr, gbc_endeJahr);

		endeStunde = new JComboBox(stundenArray);
		endeStunde.setPreferredSize(new Dimension(30, 20));
		endeStunde.setFocusable(false);
		GridBagConstraints gbc_endeStunde = new GridBagConstraints();
		gbc_endeStunde.insets = new Insets(0, 0, 5, 5);
		gbc_endeStunde.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeStunde.gridx = 5;
		gbc_endeStunde.gridy = 2;
		endeStunde.setVisible(false);
		eventDetailsPanel.add(endeStunde, gbc_endeStunde);

		endeMinute = new JComboBox(minutenArray);
		endeMinute.setPreferredSize(new Dimension(30, 20));
		endeMinute.setFocusable(false);
		GridBagConstraints gbc_endeMinute = new GridBagConstraints();
		gbc_endeMinute.insets = new Insets(0, 0, 5, 5);
		gbc_endeMinute.fill = GridBagConstraints.HORIZONTAL;
		gbc_endeMinute.gridx = 6;
		gbc_endeMinute.gridy = 2;
		endeMinute.setVisible(false);
		eventDetailsPanel.add(endeMinute, gbc_endeMinute);

		lblUhr_2 = new JLabel("Uhr");
		GridBagConstraints gbc_lblUhr_2 = new GridBagConstraints();
		gbc_lblUhr_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblUhr_2.gridx = 7;
		gbc_lblUhr_2.gridy = 2;
		lblUhr_2.setVisible(false);
		eventDetailsPanel.add(lblUhr_2, gbc_lblUhr_2);

		ortLabel = new JLabel(ort[speak]);
		ortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_ortLabel = new GridBagConstraints();
		gbc_ortLabel.fill = GridBagConstraints.BOTH;
		gbc_ortLabel.insets = new Insets(0, 0, 5, 5);
		gbc_ortLabel.gridx = 0;
		gbc_ortLabel.gridy = 3;
		eventDetailsPanel.add(ortLabel, gbc_ortLabel);

		ortTextField = new JTextField();
		ortTextField.setEditable(false);
		ortTextField.setDisabledTextColor(Color.BLACK);
		GridBagConstraints gbc_ortTextField = new GridBagConstraints();
		gbc_ortTextField.gridwidth = 7;
		gbc_ortTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_ortTextField.insets = new Insets(0, 0, 5, 5);
		gbc_ortTextField.gridx = 1;
		gbc_ortTextField.gridy = 3;
		eventDetailsPanel.add(ortTextField, gbc_ortTextField);
		ortTextField.setColumns(10);

		teilnehmerLabel = new JLabel(teilnehmer[speak]);
		teilnehmerLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_teilnehmerLabel = new GridBagConstraints();
		gbc_teilnehmerLabel.fill = GridBagConstraints.BOTH;
		gbc_teilnehmerLabel.insets = new Insets(0, 0, 5, 5);
		gbc_teilnehmerLabel.gridx = 0;
		gbc_teilnehmerLabel.gridy = 4;
		eventDetailsPanel.add(teilnehmerLabel, gbc_teilnehmerLabel);

		teilnehmerTextField = new JTextField();
		teilnehmerTextField.setDisabledTextColor(Color.BLACK);
		teilnehmerTextField.setEditable(false);
		GridBagConstraints gbc_teilnehmerTextField = new GridBagConstraints();
		gbc_teilnehmerTextField.gridwidth = 6;
		gbc_teilnehmerTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_teilnehmerTextField.insets = new Insets(0, 0, 5, 5);
		gbc_teilnehmerTextField.gridx = 1;
		gbc_teilnehmerTextField.gridy = 4;
		eventDetailsPanel.add(teilnehmerTextField, gbc_teilnehmerTextField);
		teilnehmerTextField.setColumns(10);

		participantsbutton = new JButton("+");
		GridBagConstraints gbc_participantsbutton = new GridBagConstraints();
		gbc_participantsbutton.insets = new Insets(0, 0, 5, 5);
		gbc_participantsbutton.gridx = 7;
		gbc_participantsbutton.gridy = 4;
		participantsbutton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				idEvents = (Integer) getActDeleteCandidate();
				AddContactWindow acw = new AddContactWindow(dv, false);
				acw.setVisible(true);

			}

		});
		participantsbutton.setEnabled(false);

		eventDetailsPanel.add(participantsbutton, gbc_participantsbutton);

		kalenderLabel = new JLabel(kalender[speak]);
		kalenderLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_kalenderLabel = new GridBagConstraints();
		gbc_kalenderLabel.fill = GridBagConstraints.BOTH;
		gbc_kalenderLabel.insets = new Insets(0, 0, 5, 5);
		gbc_kalenderLabel.gridx = 0;
		gbc_kalenderLabel.gridy = 5;
		eventDetailsPanel.add(kalenderLabel, gbc_kalenderLabel);

		// Kalender

		ResultSet idsCalendar;
		cals.clear();
		try {

			stat = connection.createStatement();
			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

			idsCalendar = stat
					.executeQuery("SELECT idCalendar, name, idCreator FROM Calendar WHERE idUser = "
							+ Test.iduser + ";");
			while (idsCalendar.next()) {
				CheckboxCalendar temp = new CheckboxCalendar(
						idsCalendar.getInt("idCalendar"),
						idsCalendar.getString("name"),
						idsCalendar.getInt("idCreator"));
				cals.add(temp);
			}
		} catch (SQLException e1) {
			JOptionPane
					.showMessageDialog(
							null,
							"Es konnte keine Verbindung zur Datenbank hergestellt werden",
							"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
			e1.printStackTrace();
		}

		calDropdown = new String[cals.size()];
		for (int i = 0; i < cals.size(); i++) {
			calDropdown[i] = cals.get(i).getName();
		}

		kalenderTextField = new JComboBox(calDropdown);
		kalenderTextField.setEnabled(false);
		// kalenderTextField.setDisabledTextColor(Color.BLACK);
		GridBagConstraints gbc_kalenderTextField = new GridBagConstraints();
		gbc_kalenderTextField.gridwidth = 7;
		gbc_kalenderTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_kalenderTextField.insets = new Insets(0, 0, 5, 5);
		gbc_kalenderTextField.gridx = 1;
		gbc_kalenderTextField.gridy = 5;
		eventDetailsPanel.add(kalenderTextField, gbc_kalenderTextField);
		// kalenderTextField.setColumns(10);

		label = new JLabel("  ");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 0);
		gbc_label.gridx = 8;
		gbc_label.gridy = 5;
		eventDetailsPanel.add(label, gbc_label);

		notizLabel = new JLabel(notiz[speak]);
		notizLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_notizLabel = new GridBagConstraints();
		gbc_notizLabel.fill = GridBagConstraints.BOTH;
		gbc_notizLabel.insets = new Insets(0, 0, 0, 5);
		gbc_notizLabel.gridx = 0;
		gbc_notizLabel.gridy = 6;
		eventDetailsPanel.add(notizLabel, gbc_notizLabel);

		notizTextArea = new JTextArea();
		notizTextArea.setDisabledTextColor(Color.BLACK);
		notizTextArea.setEditable(false);
		notizTextArea.setLineWrap(true);
		notizTextArea.setWrapStyleWord(true);
		JScrollPane notizScrollPane = new JScrollPane(notizTextArea);
		GridBagConstraints gbc_notizTextArea = new GridBagConstraints();
		gbc_notizTextArea.gridwidth = 8;
		gbc_notizTextArea.fill = GridBagConstraints.BOTH;
		gbc_notizTextArea.gridx = 1;
		gbc_notizTextArea.gridy = 6;
		eventDetailsPanel.add(notizScrollPane, gbc_notizTextArea);
		notizTextArea.setBorder(kalenderTextField.getBorder());

		JPanel dummyPanel1 = new JPanel();
		dummyPanel1.setBackground(new Color(r, g, b));
		dummyPanel1.setVisible(false);
		GridBagConstraints gbc_dummyPanel1 = new GridBagConstraints();
		gbc_dummyPanel1.insets = new Insets(0, 0, 0, 5);
		gbc_dummyPanel1.fill = GridBagConstraints.BOTH;
		gbc_dummyPanel1.gridx = 0;
		gbc_dummyPanel1.gridy = 1;
		contentPane.add(dummyPanel1, gbc_dummyPanel1);

		JPanel dummyPanel2 = new JPanel();
		dummyPanel2.setBackground(new Color(r, g, b));
		dummyPanel2.setVisible(false);
		GridBagConstraints gbc_dummyPanel2 = new GridBagConstraints();
		gbc_dummyPanel2.insets = new Insets(0, 0, 0, 5);
		gbc_dummyPanel2.fill = GridBagConstraints.BOTH;
		gbc_dummyPanel2.gridx = 1;
		gbc_dummyPanel2.gridy = 1;
		contentPane.add(dummyPanel2, gbc_dummyPanel2);

		buttonPanel = new JPanel();
		buttonPanel.setBackground(new Color(r, g, b));
		buttonPanel.setSize(new Dimension(400, 50));
		buttonPanel.setMinimumSize(new Dimension(400, 50));
		buttonPanel.setMaximumSize(new Dimension(400, 50));
		buttonPanel.setPreferredSize(new Dimension(400, 50));
		GridBagConstraints gbc_buttonPanel = new GridBagConstraints();
		gbc_buttonPanel.anchor = GridBagConstraints.EAST;
		gbc_buttonPanel.gridx = 2;
		gbc_buttonPanel.gridy = 1;
		contentPane.add(buttonPanel, gbc_buttonPanel);
		GridBagLayout gbl_buttonPanel = new GridBagLayout();
		gbl_buttonPanel.columnWidths = new int[] { 0, 0, 0, 0 };
		gbl_buttonPanel.rowHeights = new int[] { 0, 0, 0, 0 };
		gbl_buttonPanel.columnWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_buttonPanel.rowWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		buttonPanel.setLayout(gbl_buttonPanel);

		deleteButton = new JButton(loeschen[speak]);
		deleteButton.setEnabled(false);
		deleteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				String s = getActDeleteCandidate() + "";
				DeletebyID.deleteEvent(s);

				wv.setEs();
				wv.setTs();
				wv.getMainInstance().updateCalendar();
				forceRepaint();
				dispose();
				int y = 0;
				Date[] wa = cal.WeekData.getDateArray(wdp.getDate());

				for (int q = 0; q < wa.length; q++) {
					if (wa[q].equals(wdp.getDate())) {
						y = q;
					}
				}

				new DayView(wv, (WeekDayPanel) wv.getWeekPanel()
						.getComponent(y)).setVisible(true);
			}
		});
		deleteButton.setSize(new Dimension(110, 29));
		deleteButton.setMaximumSize(new Dimension(110, 29));
		deleteButton.setMinimumSize(new Dimension(110, 29));
		deleteButton.setPreferredSize(new Dimension(110, 29));
		GridBagConstraints gbc_deleteButton = new GridBagConstraints();
		gbc_deleteButton.insets = new Insets(0, 0, 5, 5);
		gbc_deleteButton.gridx = 0;
		gbc_deleteButton.gridy = 1;
		buttonPanel.add(deleteButton, gbc_deleteButton);

		editButton = new JButton(bearbeiten[speak]);
		editButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String text = arg0.getActionCommand();
				// /////////// BEARBEITEN
				// ///////////////////////////////////////////////////

				if (text.equals(bearbeiten[speak])) {

					titelTextField.setEditable(true);
					beginJahr.setFocusable(true); // setSelectable(true);
					beginMonat.setFocusable(true);
					beginTag.setFocusable(true);
					beginStunde.setFocusable(true);
					beginMinute.setFocusable(true);
					ortTextField.setFocusable(true);

					endeJahr.setFocusable(true);
					endeMonat.setFocusable(true);
					endeTag.setFocusable(true);
					endeStunde.setFocusable(true);
					endeMinute.setFocusable(true);

					ortTextField.setEditable(true);
					kalenderTextField.setEnabled(true);
					notizTextArea.setEditable(true);
					participantsbutton.setEnabled(true);

					beginDateTextField.setVisible(false);
					endDateTextField.setVisible(false);
					beginJahr.setVisible(true); // setSelectable(true);
					beginMonat.setVisible(true);
					beginTag.setVisible(true);
					beginStunde.setVisible(true);
					beginMinute.setVisible(true);
					endeJahr.setVisible(true);
					endeMonat.setVisible(true);
					endeTag.setVisible(true);
					endeStunde.setVisible(true);
					endeMinute.setVisible(true);

					lblUhr_1.setVisible(true);
					lblUhr_2.setVisible(true);

					// SET DATE TO RIGHT DATE //

					String begindate = beginDateTextField.getText();
					String enddate = endDateTextField.getText();

					// ARRAY: 0 = Tag, 1 = Monat, 2 = Stunde, 3 = Minute

					int[] begindatearray = getComboInts(begindate);
					int[] enddatearray = getComboInts(enddate);

					Date date = wdp.getDate();

					int byear = date.getYear();
					beginJahr.setSelectedIndex(byear - new Date().getYear());

					int bmonat;
					if (begindatearray[1] != 0) {
						bmonat = begindatearray[1];
					} else {
						bmonat = date.getMonth() + 1;
					}
					beginMonat.setSelectedIndex(bmonat - 1);

					int btag;
					if (begindatearray[0] != 0) {
						btag = begindatearray[0];
					} else {
						btag = date.getDate();
					}
					beginTag.setSelectedIndex(btag - 1);

					int bhour = begindatearray[2];
					beginStunde.setSelectedIndex(bhour);

					int bminute = begindatearray[3];
					if (bminute == 0) {
						beginMinute.setSelectedIndex(0);
					} else if (bminute > 0 && bminute < 16) {
						beginMinute.setSelectedIndex(1);
					} else if (bminute > 15 && bminute < 31) {
						beginMinute.setSelectedIndex(2);
					} else {
						beginMinute.setSelectedIndex(3);
					}

					int eyear = date.getYear();
					endeJahr.setSelectedIndex(eyear - new Date().getYear());

					int emonat;
					if (enddatearray[1] != 0) {
						emonat = enddatearray[1];
					} else {
						emonat = date.getMonth() + 1;
					}
					endeMonat.setSelectedIndex(emonat - 1);

					int etag;
					if (enddatearray[0] != 0) {
						etag = enddatearray[0];
					} else {
						etag = date.getDate();
					}
					endeTag.setSelectedIndex(etag - 1);

					int ehour = enddatearray[2];
					endeStunde.setSelectedIndex(ehour);

					int eminute = enddatearray[3];
					if (eminute == 0) {
						endeMinute.setSelectedIndex(0);
					} else if (eminute > 0 && eminute < 16) {
						endeMinute.setSelectedIndex(1);
					} else if (eminute > 15 && eminute < 31) {
						endeMinute.setSelectedIndex(2);
					} else {
						endeMinute.setSelectedIndex(3);
					}

					editButton.setText(speichern[speak]);

				}

				// ///////////// SPEICHERN
				// ////////////////////////////////////////////////////
				if (text.equals(speichern[speak])) {

					titelTextField.setEditable(false);

					beginJahr.setFocusable(false);
					beginMonat.setFocusable(false);
					beginTag.setFocusable(false);
					beginStunde.setFocusable(false);
					beginMinute.setFocusable(false);

					endeJahr.setFocusable(false);
					endeMonat.setFocusable(false);
					endeTag.setFocusable(false);
					endeStunde.setFocusable(false);
					endeMinute.setFocusable(false);

					ortTextField.setEditable(false);
					teilnehmerTextField.setEditable(false);
					kalenderTextField.setEnabled(false);
					notizTextArea.setEditable(false);
					participantsbutton.setEnabled(false);

					beginDateTextField.setVisible(true);
					endDateTextField.setVisible(true);
					beginJahr.setVisible(false); // setSelectable(true);
					beginMonat.setVisible(false);
					beginTag.setVisible(false);
					beginStunde.setVisible(false);
					beginMinute.setVisible(false);
					endeJahr.setVisible(false);
					endeMonat.setVisible(false);
					endeTag.setVisible(false);
					endeStunde.setVisible(false);
					endeMinute.setVisible(false);

					lblUhr_1.setVisible(false);
					lblUhr_2.setVisible(false);

					editButton.setText(bearbeiten[speak]);

					@SuppressWarnings("rawtypes")
					SwingWorker worker = new SwingWorker() {

						@Override
						public Object doInBackground() throws Exception {

							// ////DATE//////

							// BEGIN//
							int beginY = Integer.parseInt((String) beginJahr
									.getSelectedItem());
							int beginM = beginMonat.getSelectedIndex() + 1;
							int beginD = beginTag.getSelectedIndex() + 1;
							int beginH = beginStunde.getSelectedIndex();
							int beginMin = Integer
									.parseInt((String) beginMinute
											.getSelectedItem());

							Date begin = makeDate(beginY, beginM, beginD,
									beginH, beginMin);

							// ENDE//
							int nbeginY = Integer.parseInt((String) endeJahr
									.getSelectedItem());
							int nbeginM = endeMonat.getSelectedIndex() + 1;
							int nbeginD = endeTag.getSelectedIndex() + 1;
							int nbeginH = endeStunde.getSelectedIndex();
							int nbeginMin = Integer
									.parseInt((String) endeMinute
											.getSelectedItem());

							Date end = makeDate(nbeginY, nbeginM, nbeginD,
									nbeginH, nbeginMin);

							int selectedToDo = kalenderTextField
									.getSelectedIndex();

							int idTodo = cals.get(selectedToDo).getIdCalendar();
							System.out.println("SUUUUUUUFF");
							System.out.println(idTodo);

							// / Test ob Ende nach Begin liegt
							if ((testMonth(beginY, beginM, beginD, beginH,
									beginMin) == false)
									|| (testMonth(nbeginY, nbeginM, nbeginD,
											nbeginH, nbeginMin) == false)) {

							} else if (end.before(begin)) {

								new NotifyFrame(endevorbegin[speak])
										.setVisible(true);

							} else {

								// Dates in einen String der korrekten Form
								// bringen.
								SimpleDateFormat sdf = new SimpleDateFormat(
										"yyyy-MM-dd HH:mm:ss");

								StringBuilder sBBegin = new StringBuilder(sdf
										.format(begin));

								StringBuilder sBEnd = new StringBuilder(sdf
										.format(end));

								String beginString = sBBegin.toString();
								String endString = sBEnd.toString();

								// Liest die Werte aus

								String name = getTitelTextField().getText();
								String ort = getOrtTextField().getText();
								String notiz = getNotizTextArea().getText();

								int EventId = (Integer) getActDeleteCandidate();
								stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");
								connection.setAutoCommit(false);
								PreparedStatement pstmt = connection
										.prepareStatement("UPDATE `sopra-ws12-awesome_fireballs`.`Events` SET `idCalendar`=?, `name`=?, `startdate`=?, `enddate`=?, `location`=?, `description`=? WHERE `idEvents`=?;");

								System.out.println("HUUUUUUU");

								// Diese 2 mit Kalender ersetzen
								pstmt.setInt(1, idTodo);
								pstmt.setString(2, name);
								pstmt.setString(3, beginString);
								pstmt.setString(4, endString);
								pstmt.setString(5, ort);
								pstmt.setString(6, notiz);
								pstmt.setInt(7, EventId);
								pstmt.addBatch();

								ResultSet nextparticipantid = stat
										.executeQuery("SELECT idparticipants FROM `sopra-ws12-awesome_fireballs`.participants ORDER BY idparticipants DESC LIMIT 1;");
								int nextpartid = 0;
								while (nextparticipantid.next()) {
									nextpartid = nextparticipantid.getInt(1) + 1;
								}

								PreparedStatement ppstmt = connection
										.prepareStatement("INSERT INTO `sopra-ws12-awesome_fireballs`.participants VALUES(?, ?, ?)");

								ResultSet rsparti = getParticipantsEvent(EventId);

								while (rsparti.next()) {
									for (int i = 0; i < participants.size(); i++) {
										if (rsparti.getInt("idAdress") == participants
												.get(i)) {
											participants.remove(i);
											i = 0;
										}
									}

								}

								for (int i = 0; i < participants.size(); i++) {
									ppstmt.setInt(1, nextpartid + i);
									ppstmt.setInt(2, EventId);
									ppstmt.setInt(3, participants.get(i));
									ppstmt.addBatch();

								}
								System.out.println("TEST");

								System.out.println(pstmt.toString());
								System.out.println(ppstmt.toString());
								pstmt.executeBatch();
								ppstmt.executeBatch();
								connection.commit();
								connection.setAutoCommit(true);
								participants.clear();

							}

							return stat;
						}

						public void done() {

							if (emailLinkedList != null) {
								if (emailLinkedList.size() > 0) {
									Mail temp = new Mail();

									temp.setTo(emailLinkedList);

									temp.setBetreff("Einladung zu Termin: "
											+ titelTextField.getText());

									temp.setText(idEvents + "");

									MyModelEmail mme = new MyModelEmail();
									mme.sendMail(temp, true);

								}
							}

							wv.setEs();
							wv.setTs();
							wv.getMainInstance().updateCalendar();
							forceRepaint();
							dispose();
							int y = 0;
							Date[] wa = cal.WeekData.getDateArray(wdp.getDate());

							for (int q = 0; q < wa.length; q++) {
								if (wa[q].equals(wdp.getDate())) {
									y = q;
								}
							}

							new DayView(wv, (WeekDayPanel) wv.getWeekPanel()
									.getComponent(y)).setVisible(true);

						}

					};

					worker.execute();
				}
			}
		});
		editButton.setSize(new Dimension(110, 29));
		editButton.setMaximumSize(new Dimension(110, 29));
		editButton.setPreferredSize(new Dimension(110, 29));
		editButton.setMinimumSize(new Dimension(110, 29));
		editButton.setEnabled(false);
		GridBagConstraints gbc_editButton = new GridBagConstraints();
		gbc_editButton.insets = new Insets(0, 0, 5, 5);
		gbc_editButton.gridx = 1;
		gbc_editButton.gridy = 1;
		buttonPanel.add(editButton, gbc_editButton);

		sendButton = new JButton(senden[speak]);
		sendButton.setVisible(false);
		sendButton.setEnabled(false);
		sendButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				@SuppressWarnings("unused")
				Mail temp = new Mail();
				if (getActiveTerminArt().contains("G")) {

				}

				if (getActiveTerminArt().contains("E")) {

				}

				if (getActiveTerminArt().contains("T")) {

				}

			}
		});
		sendButton.setSize(new Dimension(110, 29));
		sendButton.setPreferredSize(new Dimension(110, 29));
		sendButton.setMaximumSize(new Dimension(110, 29));
		sendButton.setMinimumSize(new Dimension(110, 29));
		GridBagConstraints gbc_sendButton = new GridBagConstraints();
		gbc_sendButton.insets = new Insets(0, 0, 5, 0);
		gbc_sendButton.gridx = 2;
		gbc_sendButton.gridy = 1;
		buttonPanel.add(sendButton, gbc_sendButton);

		noEventsLabel = new JLabel(noTerm[speak]);
		noEventsLabel.setVisible(false);
		noEventsLabel.setFont(new Font("Lucida Grande", Font.BOLD, 18));
		eventListPanel.add(noEventsLabel);

		// Datenübernahme

		// Tag oben links wird gesetzt
		getDateLabel().setText(wdp.getDate().getDate() + "");
		// volles Datum oben rechts wird gesetzt
		getDayLabel().setText(
				intToDay(wdp.getDate().getDay()) + ", "
						+ wdp.getDate().getDate() + "."
						+ (wdp.getDate().getMonth() + 1) + "."
						+ (wdp.getDate().getYear() + 1900));

		if (wdp.getAllCalendarItems().size() < 1
				|| wdp.getAllCalendarItems() == null) {
			getNoEventsLabel().setVisible(true);
		}

		init2(wdp);

	}

	/**
	 * erzeugt die PanelListe der Termine
	 * 
	 * @param wdp
	 *            Instanz des Panels von dem aus die Tagesansichta ufgerufen
	 *            wurde
	 */
	@SuppressWarnings("deprecation")
	public void init2(WeekDayPanel wdp) {

		getEventListScrollPane().setViewportView(null);
		getEventListPanel().removeAll();
		counterTP = 0;

		// Termin Panels werden erzeugt
		for (int i = 0; i < wdp.getAllCalendarItems().size(); i++) {
			final TerminPanel tp = new TerminPanel();
			final GebTerminPanel gtp = new GebTerminPanel();

			// Abprüfen ob an Position i ein Task ist und wenn ja, Task
			// speichern
			if (wdp.getAllCalendarItems().get(i) instanceof MyTask) {
				MyTask temp = (MyTask) wdp.getAllCalendarItems().get(i);
				tp.getEventNameTextField().setText(temp.getName());
				tp.getEventNameTextField().setCaretPosition(0);

				tp.getEventDateEndTextField().setText(
						temp.getEnddate().getDate() + "."
								+ (temp.getEnddate().getMonth() + 1) + "."
								+ (temp.getEnddate().getYear() + 1900));
				tp.getEventDateEndTextField().setCaretPosition(0);
				tp.setNotiz(temp.getDescription());
				tp.setPanelType("T");
				tp.changeColor(Color.darkGray);
				tp.setTerminArt(temp.getId());

			}

			// Abprüfen ob an Position i ein Event ist und wenn ja, Event
			// speichern
			if (wdp.getAllCalendarItems().get(i) instanceof Event) {
				Event temp = (Event) wdp.getAllCalendarItems().get(i);
				tp.getEventNameTextField().setText(temp.getName());

				String start = "";
				String end = "";

				// Ruft Methode eventString auf!
				String[] startend = eventString(temp.getStart(), temp.getEnd(),
						wdp.getDate());
				start = startend[0];
				end = startend[1];
				tp.getEventDateStartTextField().setText(start);
				tp.getEventDateEndTextField().setText(end);
				tp.setNotiz(temp.getDescription());
				tp.setOrt(temp.getOrt());
				tp.setPanelType("E");
				tp.changeColor(Color.gray);
				tp.setTerminArt(temp.getEventID());

			}

			// Abprüfen ob an Position i ein Geburtstag ist und wenn ja,
			// Geburtstag speichern
			if (wdp.getAllCalendarItems().get(i) instanceof String[]) {

				String[] temp = (String[]) wdp.getAllCalendarItems().get(i);
				// Person temp = (Person) dp.getAllCalendarItems().get(i);

				gtp.getBirthdayNameTextField().setText(
						temp[0] + " " + temp[1] + " (" + temp[2]
								+ jahreKlammer[speak]);

				gtp.setPanelType("G");
			}

			// MouseListener Section
			tp.getEventNameTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());

				}
			});
			tp.getEventNamePanel().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());
				}
			});

			// tp.getEventDatePanelStart().addMouseListener(new MouseAdapter() {
			// @Override
			// public void mouseClicked(MouseEvent e) {
			// setDetailsWindow(tp);
			// }
			// });
			tp.getEventDatePanel().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());
				}
			});

			// tp.getEventDatePanelEnd().addMouseListener(new MouseAdapter() {
			// @Override
			// public void mouseClicked(MouseEvent e) {
			// setDetailsWindow(tp);
			// }
			// });

			tp.getEventDateStartTextField().addMouseListener(
					new MouseAdapter() {
						@Override
						public void mouseClicked(MouseEvent e) {
							setDetailsWindow(tp);
							setClickedPanel(tp);
							init2(getUebergabePanel2());
						}
					});

			tp.getEventDateEndTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());
				}
			});

			tp.getEventBeginnTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());
				}
			});

			tp.getEventEndeTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(tp);
					setClickedPanel(tp);
					init2(getUebergabePanel2());
				}
			});

			gtp.getBirthdayNameTextField().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setDetailsWindow(gtp);
					setClickedPanel(gtp);
					init2(getUebergabePanel2());
				}
			});

			// MouseListener Ende

			if (tp.getPanelType() == "E" || tp.getPanelType() == "T") {
				if (getClickedPanel() != null && compare(getClickedPanel(), tp)) {
					System.out.println("erkannt");
					tp.setBorder(BorderFactory
							.createLineBorder(Color.yellow, 1));
				}
				getEventListPanel().add(tp);
				counterTP++;
			}

			if (gtp.getPanelType() == "G") {
				if (getClickedPanel() != null
						&& compare(getClickedPanel(), gtp)) {
					System.out.println("erkannt");
					gtp.setBorder(BorderFactory.createLineBorder(Color.yellow,
							1));
				}
				getEventListPanel().add(gtp);
				counterGTP++;
			}
		}

		eventListPanel
				.setPreferredSize(new Dimension(
						breiteTerminPanel,
						((counterTP * hoeheTerminPanel) + (counterGTP * hoeheGebTerminPanel))));

		getEventListScrollPane().setViewportView(getEventListPanel());

	}

	public JLabel getNoEventsLabel() {
		return noEventsLabel;
	}

	public void setNoEventsLabel(JLabel noEventsLabel) {
		this.noEventsLabel = noEventsLabel;
	}

	public JTextArea getNotizTextArea() {
		return notizTextArea;
	}

	public void setNotizTextArea(JTextArea notizTextArea) {
		this.notizTextArea = notizTextArea;
	}

	public JLabel getDateLabel() {
		return DateLabel;
	}

	public void setDateLabel(JLabel dateLabel) {
		DateLabel = dateLabel;
	}

	public JLabel getDayLabel() {
		return DayLabel;
	}

	public void setDayLabel(JLabel dayLabel) {
		DayLabel = dayLabel;
	}

	public JPanel getEventDetailsPanel() {
		return eventDetailsPanel;
	}

	public void setEventDetailsPanel(JPanel eventDetailsPanel) {
		this.eventDetailsPanel = eventDetailsPanel;
	}

	public JButton getDeleteButton() {
		return deleteButton;
	}

	public void setDeleteButton(JButton deleteButton) {
		this.deleteButton = deleteButton;
	}

	public JButton getEditButton() {
		return editButton;
	}

	public void setEditButton(JButton editButton) {
		this.editButton = editButton;
	}

	public JButton getSendButton() {
		return sendButton;
	}

	public void setSendButton(JButton sendButton) {
		this.sendButton = sendButton;
	}

	public JScrollPane getEventListScrollPane() {
		return eventListScrollPane;
	}

	public void setEventListScrollPane(JScrollPane eventListScrollPane) {
		this.eventListScrollPane = eventListScrollPane;
	}

	public JTextField getTitelTextField() {
		return titelTextField;
	}

	public void setTitelTextField(JTextField titelTextField) {
		this.titelTextField = titelTextField;
	}

	public JTextField getOrtTextField() {
		return ortTextField;
	}

	public void setOrtTextField(JTextField ortTextField) {
		this.ortTextField = ortTextField;
	}

	public JTextField getTeilnehmerTextField() {
		return teilnehmerTextField;
	}

	public void setTeilnehmerTextField(JTextField teilnehmerTextField) {
		this.teilnehmerTextField = teilnehmerTextField;
	}

	public JComboBox getKalenderTextField() {
		return kalenderTextField;
	}

	public void setKalenderTextField(JComboBox kalenderTextField) {
		this.kalenderTextField = kalenderTextField;
	}

	public JPanel getEventListPanel() {
		return eventListPanel;
	}

	public void setEventListPanel(JPanel eventListPanel) {
		this.eventListPanel = eventListPanel;
	}

	public JLabel getLblDate() {
		return DateLabel;
	}

	public void setLblDate(JLabel lblDate) {
		this.DateLabel = lblDate;
	}

	public JTextField getBeginDateTextField() {
		return beginDateTextField;
	}

	public void setBeginDateTextField(JTextField beginDateTextField) {
		this.beginDateTextField = beginDateTextField;
	}

	public JTextField getEndDateTextField() {
		return endDateTextField;
	}

	public void setEndDateTextField(JTextField endDateTextField) {
		this.endDateTextField = endDateTextField;
	}

	public JLabel getLblDay() {
		return DayLabel;
	}

	public void setLblDay(JLabel lblDay) {
		this.DayLabel = lblDay;
	}

	public int getCounterTP() {
		return counterTP;
	}

	public void setCounterTP(int counterTP) {
		this.counterTP = counterTP;
	}

	public int getCounterGTP() {
		return counterGTP;
	}

	public void setCounterGTP(int counterGTP) {
		this.counterGTP = counterGTP;
	}

	public int getIdEvents() {
		return idEvents;
	}

	public void setIdEvents(int idEvents) {
		this.idEvents = idEvents;
	}

	/**
	 * Wandelt int in den entsprechenden Wochentag um
	 * 
	 * @param day
	 * @return
	 */
	public String intToDay(int day) {
		String str = "";
		switch (day) {
		case 0:
			str = so[speak];
			break;
		case 1:
			str = mo[speak];
			break;
		case 2:
			str = di[speak];
			break;
		case 3:
			str = mi[speak];
			break;
		case 4:
			str = don[speak];
			break;
		case 5:
			str = fr[speak];
			break;
		case 6:
			str = sa[speak];
			break;

		}
		return str;
	}

	/**
	 * Setzt Textfelder auf der rechten Seite
	 * 
	 * @param tp
	 *            Art des Panels welches angeklickt wurde
	 */
	public void setDetailsWindow(TerminPanel tp) {
		editButton.setEnabled(true);
		getTitelTextField().setText(tp.getEventNameTextField().getText());
		getTitelTextField().setCaretPosition(0);

		getOrtTextField().setText(tp.getOrt());
		getOrtTextField().setCaretPosition(0);
		getTeilnehmerTextField().setText(tp.getTeilnehmer());
		getTeilnehmerTextField().setCaretPosition(0);
		kalenderTextField.setVisible(true);
		// getKalenderTextField().setText(tp.getCalendar());
		// getKalenderTextField().setCaretPosition(0);
		getNotizTextArea().setText(tp.getNotiz());
		getNotizTextArea().setCaretPosition(0);
		setActDeleteCandidate(tp.getTerminArt());
		System.out.println("Termin ID:  " + getActDeleteCandidate());
		setActiveTerminArt(tp.getPanelType());
		System.out.println("Aktueller Typ: " + getActiveTerminArt());
		if (getActiveTerminArt().contains("G")) {
			getDeleteButton().setEnabled(false);
			getSendButton().setEnabled(false);
			getEditButton().setEnabled(false);
		} else if (getActiveTerminArt().contains("T")) {
			getDeleteButton().setEnabled(false);
			getSendButton().setEnabled(true);
			getEditButton().setEnabled(false);
		} else {
			getDeleteButton().setEnabled(true);
			getSendButton().setEnabled(true);
			getEditButton().setEnabled(true);

		}
		setActiveEvent(tp, null);

		// SETZT SELECTED DATUM

		String sDateStart = tp.getEventDateStartTextField().getText();

		getBeginDateTextField().setText(sDateStart);

		String sDateEnd = tp.getEventDateEndTextField().getText();

		getEndDateTextField().setText(sDateEnd);

		// SETZT TEILNEHMER

		int id = (Integer) getActDeleteCandidate();
		try {
			stat = connection.createStatement();
		} catch (SQLException e1) {
			JOptionPane
					.showMessageDialog(
							null,
							"Es konnte keine Verbindung zur Datenbank hergestellt werden",
							"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
			e1.printStackTrace();
		}
		if (getActiveTerminArt().contains("T")) {

			String participantTaskString = "";

			try {
				ResultSet participantsTask = getParticipantsTask(id);

				while (participantsTask.next()) {

					if (participantsTask.isLast()) {

						participantTaskString = participantTaskString
								+ participantsTask.getString("fname") + " "
								+ participantsTask.getString("lname");

					} else {

						participantTaskString = participantTaskString
								+ participantsTask.getString("fname") + " "
								+ participantsTask.getString("lname") + ", ";

					}
				}
			} catch (SQLException e) {
				JOptionPane
						.showMessageDialog(
								null,
								"Es konnte keine Verbindung zur Datenbank hergestellt werden",
								"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
			}
			teilnehmerTextField.setText(participantTaskString);

		}
		if (getActiveTerminArt().contains("E")) {

			participants.clear();
			String participantEventString = "";

			try {
				ResultSet participantsEvent = getParticipantsEvent(id);

				while (participantsEvent.next()) {

					if (participantsEvent.isLast()) {
						participants.add(participantsEvent.getInt("idAdress"));

						participantEventString = participantEventString
								+ participantsEvent.getString("fname") + " "
								+ participantsEvent.getString("lname");

					} else {
						participants.add(participantsEvent.getInt("idAdress"));

						participantEventString = participantEventString
								+ participantsEvent.getString("fname") + " "
								+ participantsEvent.getString("lname") + ", ";

					}
				}
			} catch (SQLException e) {
				JOptionPane
						.showMessageDialog(
								null,
								"Es konnte keine Verbindung zur Datenbank hergestellt werden",
								"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
			}
			teilnehmerTextField.setText(participantEventString);

		}

		// / SETZTE KALENDER

		idCal = 0;
		if (getActiveTerminArt().contains("T")) {

			try {
				ResultSet task = getTask(id);
				task.next();
				idCal = task.getInt("idToDo");
			} catch (SQLException e) {
				JOptionPane
						.showMessageDialog(
								null,
								"Es konnte keine Verbindung zur Datenbank hergestellt werden",
								"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
			}
		}

		if (getActiveTerminArt().contains("E")) {

			try {
				ResultSet event = getEvent(id);
				event.next();
				idCal = event.getInt("idCalendar");

			} catch (SQLException e) {
				JOptionPane
						.showMessageDialog(
								null,
								"Es konnte keine Verbindung zur Datenbank hergestellt werden",
								"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
			}
		}

		try {
			if (idCal != 0) {
				ResultSet cal = getCalendar(idCal);
				cal.next();
				String posName = cal.getString("name");
				kalenderTextField.setEnabled(true);
				kalenderTextField.setSelectedItem(posName);

				kalenderTextField.setEnabled(false);

			}

		} catch (SQLException e) {
			JOptionPane
					.showMessageDialog(
							null,
							"Es konnte keine Verbindung zur Datenbank hergestellt werden",
							"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}

	}

	/**
	 * Setzt die Textfelder auf der rechten Seite
	 * 
	 * @param gtp
	 *            Art des Panels auf das geklickt wurde
	 */
	public void setDetailsWindow(GebTerminPanel gtp) {
		getTitelTextField().setText(gtp.getBirthdayNameTextField().getText());
		getTitelTextField().setCaretPosition(0);
		getOrtTextField().setText("");
		getOrtTextField().setCaretPosition(0);
		getTeilnehmerTextField().setText("");
		getTeilnehmerTextField().setCaretPosition(0);
		kalenderTextField.setVisible(false);

		getNotizTextArea().setText("");
		getNotizTextArea().setCaretPosition(0);
		setActiveEvent(null, gtp);
		setActiveTerminArt(gtp.getPanelType());
		if (getActiveTerminArt().contains("G")) {
			getDeleteButton().setEnabled(false);
			getSendButton().setEnabled(false);
			getEditButton().setEnabled(false);
		} else if (getActiveTerminArt().contains("T")) {
			getDeleteButton().setEnabled(false);
			getSendButton().setEnabled(true);
			getEditButton().setEnabled(false);
		} else {
			getDeleteButton().setEnabled(true);
			getSendButton().setEnabled(true);
			getEditButton().setEnabled(true);

		}
	}

	/**
	 * Tut nichts
	 * 
	 * @param tp
	 *            das eine Panel
	 * @param gtp
	 *            das andere Panel
	 */
	public void setActiveEvent(TerminPanel tp, GebTerminPanel gtp) {
		if (tp != null) {

		}

		if (gtp != null) {

		}

	}

	/*
	 * Liefert ein String Array mit zwei Strings für die Eventzeiten. Der erste
	 * ist die Startzeit. Der zweite ist die Entzeit. Wenn es ein mehr tägiges
	 * Event ist mit Datum sonst ohne.
	 */

	@SuppressWarnings("deprecation")
	public String[] eventString(Date sd, Date ed, Date aktuell) {
		String[] rueckgabe = new String[2];

		// Fügt die Nullen bei den Minuten hinzu

		String m1 = "";
		String m2 = "";

		if (sd.getMinutes() < 10) {
			m1 = "0" + sd.getMinutes();
		} else {
			m1 = sd.getMinutes() + "";
		}

		if (ed.getMinutes() < 10) {
			m2 = "0" + ed.getMinutes();
		} else {
			m2 = ed.getMinutes() + "";
		}

		// Setzt AM / PM wenn Englisch

		String h1 = "";
		String h2 = "";
		String sz = uhr[speak];
		String ez = uhr[speak];

		int hi1 = sd.getHours();

		int hi2 = ed.getHours();

		if (format == 1) {
			sz = " am";
			ez = " am";
			if (hi1 > 12) {
				hi1 -= 12;
				sz = " pm";

			}
			if (hi2 > 12) {
				hi2 -= 12;
				ez = " pm";
			}

		}
		h1 = hi1 + "";
		h2 = hi2 + "";

		// Wenn Event am entsprechendem Tag beginnt und endet.

		if (ed.getDate() == aktuell.getDate()
				&& ed.getMonth() == aktuell.getMonth()
				&& ed.getYear() == aktuell.getYear()
				&& sd.getDate() == aktuell.getDate()
				&& sd.getMonth() == aktuell.getMonth()
				&& sd.getYear() == aktuell.getYear()) {

			rueckgabe[0] = h1 + ":" + m1 + sz;
			rueckgabe[1] = h2 + ":" + m2 + ez;

		}

		else {

			rueckgabe[0] = "(" + sd.getDate() + "." + (sd.getMonth() + 1)
					+ ".)  " + h1 + ":" + m1 + sz;
			rueckgabe[1] = "(" + ed.getDate() + "." + (ed.getMonth() + 1)
					+ ".)  " + h2 + ":" + m2 + ez;
		}

		return rueckgabe;
	}

	public Object getActDeleteCandidate() {
		return actDeleteCandidate;
	}

	public void setActDeleteCandidate(Object actDeleteCandidate) {
		this.actDeleteCandidate = actDeleteCandidate;
	}

	public String getActiveTerminArt() {
		return activeTerminArt;
	}

	public void setActiveTerminArt(String activeTerminArt) {
		this.activeTerminArt = activeTerminArt;
	}

	public JPanel getClickedPanel() {
		return clickedPanel;
	}

	public void setClickedPanel(JPanel clickedPanel) {
		this.clickedPanel = clickedPanel;
	}

	public DayPanel getUebergabePanel() {
		return uebergabePanel;
	}

	public void setUebergabePanel(DayPanel uebergabePanel) {
		this.uebergabePanel = uebergabePanel;
	}

	public WeekDayPanel getUebergabePanel2() {
		return uebergabePanel2;
	}

	public void setUebergabePanel2(WeekDayPanel uebergabePanel2) {
		this.uebergabePanel2 = uebergabePanel2;
	}

	/**
	 * vergleicht ob 2 Panel identisch sind
	 * 
	 * @param p
	 *            das eine Panel
	 * @param tp
	 *            das andere Panel
	 * @return Boolean true wenn Panels identisch
	 */
	public Boolean compare(JPanel p, TerminPanel tp) {
		Boolean b = false;

		if (p instanceof TerminPanel) {
			if (tp.getEventNameTextField()
					.getText()
					.equals(((TerminPanel) p).getEventNameTextField().getText())
					&& tp.getEventDateStartTextField()
							.getText()
							.equals(((TerminPanel) p)
									.getEventDateStartTextField().getText())
					&& tp.getEventDateEndTextField()
							.getText()
							.equals(((TerminPanel) p)
									.getEventDateEndTextField().getText())) {
				b = true;
			}
		}

		return b;

	}

	/**
	 * vergleicht ob 2 Panels identisch sind
	 * 
	 * @param p
	 *            Das eine panel
	 * @param gtp
	 *            das andere Panel
	 * @return Boolean true wenn Panels identisch
	 */
	public Boolean compare(JPanel p, GebTerminPanel gtp) {
		Boolean b = false;
		if (p instanceof GebTerminPanel) {
			if (gtp.getBirthdayNameTextField()
					.getText()
					.equals(((GebTerminPanel) p).getBirthdayNameTextField()
							.getText())) {
				b = true;
			}
		}

		return b;

	}

	/**
	 * Gibt die Combo Ints
	 * 
	 * @param s
	 *            String der Combo Ints
	 * @return Gibt Interger Array zurück mit den Combo ints
	 */
	public static int[] getComboInts(String s) {

		int tag = 0;
		int monat = 0;
		int stunde = 0;
		int minute = 0;

		// WENN ERSTES ZEICHEN EINE KLAMMER IST
		// ALSO >>>> MEHRTAEGIGES EREIGNIS <<<<

		char erstesZeichen = s.charAt(0);
		if (erstesZeichen == '(') {

			String[] gS = s.split(" ");

			String[] dS = gS[0].split("\\.");

			// TAG
			if (dS[0].length() == 3) {
				String s1 = dS[0].charAt(1) + "";
				String s2 = dS[0].charAt(2) + "";
				tag = Integer.parseInt(s1 + s2);
			}

			else {
				tag = Integer.parseInt((dS[0].charAt(1) + ""));
			}

			// MONAT
			monat = 0;
			if (dS[1].length() == 2) {
				String s1 = dS[1].charAt(0) + "";
				String s2 = dS[1].charAt(1) + "";
				monat = Integer.parseInt(s1 + s2);
			} else {
				monat = Integer.parseInt((dS[1].charAt(0) + ""));
			}

			String[] zS = gS[2].split(':' + "");
			// STUNDE
			if (zS[0].length() == 2) {
				String s1 = zS[0].charAt(0) + "";
				String s2 = zS[0].charAt(1) + "";
				stunde = Integer.parseInt(s1 + s2);
			} else {

				stunde = Integer.parseInt(zS[0].charAt(0) + "");
			}

			// MINUTE
			String ms1 = zS[1].charAt(0) + "";
			String ms2 = zS[1].charAt(1) + "";
			minute = Integer.parseInt(ms1 + ms2);

		}

		// WENN ERSTES ZEICHEN KEINE KLAMMER IST
		// ALSO >>>> EINTÄGIGES EREIGNIS <<<<
		else {

			String[] superS = s.split(':' + "");

			// STUNDE
			if (superS[0].length() == 2) {
				String s1 = superS[0].charAt(0) + "";
				String s2 = superS[0].charAt(1) + "";
				stunde = Integer.parseInt(s1 + s2);
			} else {
				stunde = Integer.parseInt(superS[0].charAt(0) + "");
			}

			// MINUTE
			String ms1 = superS[1].charAt(0) + "";
			String ms2 = superS[1].charAt(1) + "";
			minute = Integer.parseInt(ms1 + ms2);

		}

		int[] rueck = { tag, monat, stunde, minute };
		System.out.println("T " + tag + "M " + monat + "S " + stunde + "M "
				+ minute);
		return rueck;
	}

	/**
	 * Stellt Verbindung zur DB her
	 * 
	 * @return
	 */
	// public boolean connect() {
	//
	// try {
	// Class.forName("com.mysql.jdbc.Driver");
	// connection = DriverManager
	// .getConnection("jdbc:mysql://win9142.informatik.uni-wuerzburg.de:3306?user=awesomefireballs&password=jesus");
	//
	// } catch (ClassNotFoundException e) {
	//
	// e.printStackTrace();
	// } catch (SQLException e) {
	// JOptionPane.showMessageDialog(null,
	// "Es konnte keine Verbindung zur Datenbank hergestellt werden",
	// "Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
	// e.printStackTrace();
	// return false;
	// }
	//
	// return true;
	// }

	/**
	 * Gibt ein RS mit allen Teilnehmern von einem Task zurueck
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getParticipantsTask(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Adress.* FROM Task, participantsToDo, Adress where Task.idTask = "
						+ idString
						+ "AND Adress.idAdress = participantsToDo.idAdress AND participantsToDo.idTask = Task.idTask group by Adress.idAdress;");

		return rs;

	}

	/**
	 * Gibt ein RS mit allen Teilnehmern von einem Task zurueck
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getParticipantsEvent(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Adress.* FROM Events, participants, Adress where Events.idEvents = "
						+ idString
						+ "AND Adress.idAdress = participants.idAdress AND participants.idEvents = Events.idEvents group by Adress.idAdress;");

		return rs;

	}

	/**
	 * Gibt ein RS mit bestimmtem Task
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getTask(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Task.* FROM Task where Task.idTask = "
						+ idString + ";");

		return rs;

	}

	/**
	 * Gibt ein RS mit bestimmtem Event
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getEvent(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Events.* FROM Events where Events.idEvents = "
						+ idString + ";");

		return rs;

	}

	/**
	 * Gibt ein RS mit bestimmtem Calendar
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getCalendar(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Calendar.* FROM Calendar where Calendar.idCalendar = "
						+ idString + ";");

		return rs;

	}

	/**
	 * Erzeugt Datum aus einzelnen Integern
	 * 
	 * @param year
	 *            Jahr
	 * @param month
	 *            Monat
	 * @param day
	 *            Tag
	 * @param hour
	 *            Stunden
	 * @param minute
	 *            Minuten
	 * @return Datum mit eingegeben Werten
	 */
	@SuppressWarnings("deprecation")
	public static Date makeDate(int year, int month, int day, int hour,
			int minute) {

		return new Date(year - 1900, month - 1, day, hour, minute);

	}

	/**
	 * Prüft ob Werte sinnvoll sind
	 * 
	 * @param year
	 *            Jahr
	 * @param month
	 *            Monat
	 * @param day
	 *            tag
	 * @param hour
	 *            Stunden
	 * @param minute
	 *            Minuten
	 * @return Boolean, true wenn werte sinnvoll
	 */
	@SuppressWarnings("deprecation")
	public Boolean testMonth(int year, int month, int day, int hour, int minute) {
		// Date datumAktuell = new Date();
		//
		//
		// // Variablen fuer das Datum
		// int aktuJahr = datumAktuell.getYear() + 1900;
		// int m = datumAktuell.getMonth() + 1;
		// int t = datumAktuell.getDate();
		// int h = datumAktuell.getHours();

		// Prueft ob ints Sinn ergeben
		if (year < 1900 || month < 1 || month > 12 || day < 1 || day > 31
				|| hour < 0 || hour > 23 || minute < 0 || minute > 45) {

			new NotifyFrame(unbekannterfehler[speak]).setVisible(true);
			return false;

		}

		// Prueft ob es den Tag in diesem Monat gibt.
		else if (day > monthLength(new Date(year - 1900, month - 1, 1))) {

			new NotifyFrame("Dieser Monat besitzt diesen Tag nicht.")
					.setVisible(true);
			return false;
		}

		else {
			return true;
		}

	}

	/**
	 * Setzt Teilnehmer aus einer LinkedList
	 * 
	 * @param ll
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void setParticipants(LinkedList ll) {
		this.participants = ll;
	}

	/**
	 * Setzt in der Datenbank die Teilnehmer
	 */
	public void setParticipantsText() {
		emailLinkedList = new LinkedList<String>();
		String s = "";
		String mail = "";
		try {
			stat = connection.createStatement();

			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

			for (int i = 0; i < participants.size(); i++) {
				ResultSet rs = stat
						.executeQuery("SELECT Adress.* FROM Adress WHERE idAdress= "
								+ participants.get(i) + ";");
				rs.next();
				s += rs.getString("fname") + " ";
				s += rs.getString("lname") + ", ";
				mail = rs.getString("email");
				emailLinkedList.add(mail);
			}
		} catch (SQLException e) {
			JOptionPane
					.showMessageDialog(
							null,
							"Es konnte keine Verbindung zur Datenbank hergestellt werden",
							"Haaalt! Stop!", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}

		teilnehmerTextField.setText(s);
	}

	/**
	 * Berechnet Monatslänge
	 * 
	 * @param d
	 *            Datum des Monats, dessen Monatslänge berecnet werden soll
	 * @return Integer mit der Länge des Monats
	 */
	@SuppressWarnings("deprecation")
	public static int monthLength(Date d) {

		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, d.getYear());
		cal.set(Calendar.MONTH, d.getMonth());
		cal.set(Calendar.DATE, d.getDate());

		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}

	public void forceRepaint() {
		paint(getGraphics());
	}

}
